Phpmysqlinsertintowhile ended unexpectedly

Source: Internet
Author: User
Phpmysqlinsertintowhile ended unexpectedly
$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 ..


Reply to discussion (solution)

PS: the processed data is Chinese. There are 0.19 million pieces of data, about 11 MB. the server uses apache. is it terminated only when the server is under heavy load?

..
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

I can say batch/batch processing
For more information, see the downstairs ......

# Write the file on the second floor and read it again. I have just tried it, but it still doesn't work. After 1 K inserts, it will be terminated for unknown reasons.
Depending on the processing capability (about 1000 items), how many times does it take if I want to batch process (# The method described on the third floor? I have 20 million records ..

Won't you write a single insert?
Of course, a 1 K insert statements will drag mysql down.
Insert multiple data records in a single insert statement.

Try using stored procedures?

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;

Won't you write a single insert?
Of course, a 1 K insert statements will drag mysql down.
Insert multiple data records in a single insert statement.
Insert... values (), (), ()... is that true?

Try using stored procedures?
What does stored procedure mean? I have not learned.

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, c ......
This is a great God! Too strong! This method works very well, and it will be finished in 9.15S.

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;

Excuse me, what does it mean to directly use SQL commands without changing php?
Is it possible to create an SQL file using PHP and then execute the SQL statement?

I also encountered the same problem, but I still haven't solved it...

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.