The loss of data imported into mysql in Excel last night has not been solved. please come here for help. thank you for choosing for ($ j = 3; $ j & lt ;=$ highestRow; $ j ++) // The header is not read. {$ a & nbsp ;=& nbsp; $ objPHPExcel-& gt; getActi Excel data is lost when importing mysql data.
I did not solve the problem for one night last night. come here for help. thank you!
For ($ j = 3; $ j <= $ highestRow; $ j ++) // The header is not read.
{
$ A = $ objPHPExcel-> getActiveSheet ()-> getCell ("A". $ j)-> getValue ();
$ A = iconv ("UTF-8", "GBK // IGNORE", $ a); // transcode
$ B = $ objPHPExcel-> getActiveSheet ()-> getCell ("B". $ j)-> getValue ();
$ B = iconv ("UTF-8", "GBK // IGNORE", $ B); // transcode
// $ C = $ objPHPExcel-> getActiveSheet ()-> getCell ("C". $ j)-> getValue ();
// $ D = $ objPHPExcel-> getActiveSheet ()-> getCell ("D". $ j)-> getValue ();
// $ E = $ objPHPExcel-> getActiveSheet ()-> getCell ("E". $ j)-> getValue ();
$ SQL = "INSERT INTO paee_course VALUES ('". $. "','". $ B. "')";//,". $ c. ",". $ d. ",". $ e."
Echo $ SQL. "$ j
";
Mysql_query ($ SQL );
/* If (! Mysql_query ($ SQL ))
{
Re_result ("failed to import data. please try again later or contact the administrator ");
}*/
}
Problem:
1. all outputs on the page are successfully output, but only 67 are imported into the database.
2. the page output last night was garbled, and the imported database was garbled. After I converted the code, the page output was normal, but it was still garbled after the database was imported, but it was not garbled during the import in the morning. I didn't change the code. why?
Thank you!
------ Solution --------------------
1. garbled
PHPExcel reads data in UTF-8 encoding by default and does not need to be changed unless otherwise specified.
If mysql is set to the gbk character set, manual transcoding is not required after reading. You only need to execute set names utf8 after connecting to the database. Mysql will automatically complete transcoding
Reduces code and reduces the probability of problems.
2. data loss
Robust code, that is, code containing error handling. At least.
Mysql_query ($ SQL) or die (mysql_error ());
So that you can see what went wrong.
After you read the data, insert it to the database without any processing.
So if the data contains the special character "'", will there be no error?
------ Solution --------------------
This is because your table has too much data.
Changing your primary key to a signed long integer (int) to an Unsigned int doubles the capacity.
2147483647 is the 31 power of 2-1
That is, the maximum number that a signed long integer can represent.
The unsigned long integer can be expressed as 4294967296.
Of course, the primary key does not have negative numbers.