Phpmysqlinsertintowhile accidental termination PHPcode $ result = mysql_query (& quot; SELECTuid, pid, cateFROMupcm & quot;); while ($ rows = m php mysql insert into while accidental termination
PHP code
$result = mysql_query("SELECT uid , pid , cate FROM upcm");while($rows = mysql_fetch_row($result)){$arry = explode($sepr,$rows[2],5);$query = "INSERT INTO upcn(uid,pid,cate1,cate2,cate3,cate4,cate5) VALUES('$rows[0]','$rows[1]','$arry[0]','$arry[1]','$arry[2]','$arry[3]','$arry[4]')";$result1 = mysql_query($query);if(!$result1){echo "fail
";}}
Mysql_fetch_row ($ result) gets the query results and processes them one by one. after processing the results, it is written into a new table. However, every execution of the while loop is always terminated before the program is executed, if no data is processed, replace insert into with printf ("**"); instead of insert, the program is correctly executed, and the number of inserts for each running program is different, sometimes there are many and sometimes few. what is the situation of the heroes? I am so upset ..
------ Solution --------------------
..
You must run a single SQL statement in cli mode to handle such problems !!!
You have to export the data first and then import the data, instead of doing so.
See select
------ Solution --------------------
You need to troubleshoot the following issues:
1. php timeout
2. web server timeout
3. special characters are not escaped
4. count ($ array) <5
Algorithm considerations:
INSERT statements that assemble thousands of values into multiple values
Insert segments by page
Directly use SQL commands, without changing php
$ SQL = <SQL
Insert into upcn (uid, pid, cate1, cate2, cate3, cate4, cate5)
SELECT uid, pid
, Substring_index (cate, '$ sepr', 1),' $ sepr',-1)
, Substring_index (cate, '$ sepr', 2),' $ sepr',-1)
, Substring_index (cate, '$ sepr', 3),' $ sepr',-1)
, Substring_index (cate, '$ sepr', 4),' $ sepr',-1)
, Substring_index (cate, '$ sepr', 5),' $ sepr',-1)
FROM upcm
SQL;