Excel file import MySQL Error

Source: Internet
Author: User
Excel file import MySQL Error
In the table is very simple, just 12 columns of data, to import MySQL
Find the code on the Internet, your own test files and downloaded files are in a folder,
There are four files 1,data.xls 2.index.php 3,reader.php (downloaded) 4,oleread.inc (downloaded)

Data.xls Data in the table
Num,names,years,season,groups,colornote,colornum,price,types,sizes,materials,note
There are two lines of records

The index code is as follows
 Require_once ' reader.php '; Excelfile ($filename, $encoding); $data = new Spreadsheet_excel_reader (); Set output Encoding. $data->setoutputencoding (' GBK ');
"Data.xls" means an Excel file to import into MySQL
$data->read (' Data.xls ');
@ $db = mysql_connect (' localhost ', ' root ', ' 123123 ') or
Die ("Could not connect to database."); /Connection Database
mysql_query ("Set names ' GBK '");//Output Chinese
mysql_select_db (' Test '); Select Database
Error_reporting (e_all ^ e_notice);
for ($i = 1; $i <= $data->sheets[0][' numrows '); $i + +) {
The For loop of the following comments prints the Excel table data
/*
for ($j = 1; $j < = $data->sheets[0][' numcols '); $j + +) {
echo "\" ". $data->sheets[0][' cells ' [$i] [$j]." \",";
}
echo "\ n";
*/
The following code inserts the Excel table data "3 fields" into MySQL,
Depending on how much of your Excel table field, rewrite the following code!
$sql = "INSERT into test
(
Num,names,years,season,groups,colornote,colornum,price,types,sizes,materials,note
)
VALUES (' ".
$data->sheets[0][' cells ' [$i][1]. "', '".
$data->sheets[0][' cells ' [$i][2]. "', '".
$data->sheets[0][' cells ' [$i][4]. "', '".
$data->sheets[0][' cells ' [$i][5]. "', '".
$data->sheets[0][' cells ' [$i][6]. "', '".
$data->sheets[0][' cells ' [$i][7]. "', '".
$data->sheets[0][' cells ' [$i][8]. "', '".
$data->sheets[0][' cells ' [$i][9]. "', '".
$data->sheets[0][' cells ' [$i][10]. "', '".
$data->sheets[0][' cells ' [$i][11]. "', '".
$data->sheets[0][' cells '] [$i][12]. "')";
echo $sql. ' < br/> ';
$res = mysql_query ($sql);
}
?>


Run index.php report the following error

Fatal Error:call to a member function read () on a non-object in D:\AppServ\www\aaee\index.php on line 4
------Solution--------------------
Line 4th $data->read (' Data.xls ');
Where did this and $data be instantiated?

Obviously you are too careless, the code copied from the Internet is not carefully organized
The sentence $data = new Spreadsheet_excel_reader (); Not yet in the comments in the second line?
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.