PHP MySQL insert into while unexpected termination
$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] ') ";
$result 1 = mysql_query ($query);
if (! $result 1)
{
echo "fail
";
}
}
Mysql_fetch_row ($result) Gets the result of the query, processing it, and then writing it into a new table, but every time the while loop is executed, the program terminates without finishing the data, replacing insert INTO printf ("* *") , instead of inserting the operation, the program will be executed correctly, and each time the program is inserted into a different number of bars, sometimes less, ask the heroes what the situation this is, distress ah.
Share to:
------Solution--------------------
。。
Like your problem, must be in the CLI mode to run a single SQL processing to be reliable AH!!!
You have to export the data first, and then import it, instead of doing it.
See SELECT INTO
------Solution--------------------
There are several issues to be aware of exclusions:
1. PHP Timeout
2. Web server timeout
3. Special characters not escaped
4, COUNT ($array) < 5
The algorithm can consider:
Inserts every thousand INSERT statements that are assembled into multiple value
Insert by Segment in a paginated manner
Use SQL instructions directly, without changing hands with PHP
$sql =<<< SQL
INSERT into UPCN (uid,pid,cate1,cate2,cate3,cate4,cate5)
SELECT UID, PID
, Substring_index (Substring_index (Cate, ' $sepr ', 1), ' $sepr ',-1)
, Substring_index (Substring_index (Cate, ' $sepr ', 2), ' $sepr ',-1)
, Substring_index (Substring_index (Cate, ' $sepr ', 3), ' $sepr ',-1)
, Substring_index (Substring_index (Cate, ' $sepr ', 4), ' $sepr ',-1)
, Substring_index (Substring_index (Cate, ' $sepr ', 5), ' $sepr ',-1)
From UPCM
SQL;