0

Hi,

I was trying to import the excel values in mysql DB. While trying, am facing this error. Please help me out:

Fatal error: Call to undefined function mysql_real_espace_string() in E:\xampp\htdocs\read.php on line 49

CODING:

<?php
ini_set('memory_limit', '16M');
set_time_limit(0);
require_once("E:/xampp/htdocs/phpexcel/Classes/PHPExcel.php");

$inputFileName='./xls/test_data.xls';

/** Identify the type of  $inputFileName **/
$inputFileType=PHPExcel_IOFactory::identify($inputFileName);

/** Create a new reader of the type that has been identified **/
$objReader=PHPExcel_IOFactory::createReader($inputFileType);

/**Load $inputFileName to a PHPExcel object **/
$objPHPExcel=$objReader->load($inputFileName);

/**Get the calculated value from a cell**/
$worksheet='Worksheet';

#$cell='A1';
/**Get a normal value from a cell **/
#$cellValue=$objPHPExcel->getSheetByName($worksheet)->getCell($cell)->getCalculatedValue();

$worksheet=$objPHPExcel->getActiveSheet();

$highestRow = $worksheet->getHighestRow(); 
$highestColumn = $worksheet->getHighestColumn(); 

$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); 


$myServer = "local";
	$myUser = "zzzz";
	$myPass = "yyyy";
	$myDB = "xxxx"; 
	
	//connection to the database
	$dbhandle = mysql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer");
  
    //select a database to work with
	$selected = mysql_select_db($myDB, $dbhandle)	or die("Couldn't open database $myDB");
    

$row = array();
for ($row = 1; $row <= $highestRow; ++$row) 
{
  for ($col = 0; $col <= $highestColumnIndex; ++$col) 
  {
    $row[$col] = mysql_real_espace_string($worksheet->getCellByColumnAndRow($col, $row)->getValue());
  }

    mysql_query("INSERT INTO test (name,hours) VALUES ($row[1],$row[2])") or die("can't insert");
}

?>

Thanks....

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by jacksantho
0

because you have a typo in the function and the correct one is

<?php mysql_real_escape_sting()?>
0

lol not mysql_real_escape_sting, but mysql_real_escape_string
those damn typos hahaha

0

LOL :D
that was very funny :D
as 54uydf said in replace line 49 in ur script with this line

$row[$col] = mysql_real_escape_string($worksheet->getCellByColumnAndRow($col, $row)->getValue());
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.