Phpmysqlinsertintowhile ended unexpectedly

Source: Internet
Author: User
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;

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.