An error occurred while importing the EXCEL file to MYSQL.

Source: Internet
Author: User
An error occurred while importing the EXCEL file to MYSQL. This post was last written by xuzuning from 2013-11-1413: 36: Large & nbsp; 2. index. php & nbsp; 3. an error occurred while importing the reader EXCEL file to MYSQL.

This post was last edited by xuzuning at 13:36:39, January 14 ,.

The table contains 12 columns of data.
The code found on the Internet, the files tested and downloaded are all in one folder,
There are four files: 1. data.xls 2. index. php 3, reader. php (downloaded) 4, oleread. inc (downloaded)

Data in data.xls table
Num, names, years, season, groups, colornote, colornum, price, types, sizes, materials, note
There are two rows 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 refers to the excel file to be imported to mysql.
$ Data-> read('data.xls ');
@ $ Db = mysql_connect ('localhost', 'root', '123') or
Die ("cocould not connect to database."); // connect to the database
Mysql_query ("set names 'gbk'"); // output Chinese
Mysql_select_db ('test'); // select a database
Error_reporting (E_ALL ^ E_NOTICE );
For ($ I = 1; $ I <= $ data-> sheets [0] ['numrows ']; $ I ++ ){
// Print the excel table data in a for loop with the following comments
/*
For ($ j = 1; $ j <= $ data-> sheets [0] ['numcols']; $ j ++ ){
Echo "\" ". $ data-> sheets [0] ['cells '] [$ I] [$ j]." \ ",";
}
Echo "\ n ";
*/
// The following code inserts [3 fields] of the excel table data into mysql,
// Rewrite the following code based on the number of fields in your excel table!
$ 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 );
}
?>


The following error is reported when you run index. php.

Fatal error: Call to a member function read () on a non-object in D: \ AppServ \ www \ aaee \ index. php on line 4

Share: More


------ Solution --------------------
Row 4th $ data-> read('data.xls ');
Where is this instantiated with $ data?

Obviously, you are too careless. the code copied from the Internet is not carefully organized.
$ Data = new Spreadsheet_Excel_Reader (); isn't it still in the comments of the second line?

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.