PHP MySQL insert into while unexpected termination, how to handle

Source: Internet
Author: User
Tags mysql insert php mysql
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;
  • 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.