Php updates the database in batches, but the memory is insufficient. it cannot be changed.

Source: Internet
Author: User
Php batch updates the database, but it shows that the memory is insufficient and cannot be changed. Please submit the Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 36 bytes) in E: \ phpStudy \ WWW \ redis \ update. php on line 12

$ SQL = "select * from user_invite where invite ='' "; // Construct a query statement $ result_row = mysql_query ($ SQL); if (! $ Result_row) {die ("cocould not to the database
". Mysql_error ();} $ row = mysql_fetch_array ($ result_row, MYSQL_ASSOC); if ($ row) {$ arr = array (); while ($ row) {$ arr [] = $ row;} foreach ($ arr as $ key => $ val) {$ ids = $ val ['id']; // $ SQL = "update user_invite set invite ='' where invite! = ''"; $ Sqls = "update user_invite set invite = '". make_coupon_card (). "', addtime = '". time (). "'Where invite ='' and id = '". $ ids. "'"; print_r ($ sqls); // exit; $ result = mysql_query ($ sqls); // execute update // unset ($ value );} echo "batch generation completed";} else {echo "generated ";}


Reply to discussion (solution)

While ($ row ){
....
}
Aren't you an endless loop?

While ($ row ){
....
}
Aren't you an endless loop?


How can I improve my skills? I hope you will not hesitate to give me some advice.

$ SQL = "select * from user_invite where invite ='' "; // Construct a query statement
$ Result_row = mysql_query ($ SQL );

If (! $ Result_row)
{
Die ("cocould not to the database
". Mysql_error ());
}
$ Row = mysql_fetch_array ($ result_row, MYSQL_ASSOC );

If ($ row ){
$ Arr = array ();
While (! Empty ($ row )){
$ Arr [] = $ row;

Foreach ($ arr as $ key => $ val)
{
$ Ids = $ val ['id'];
// $ SQL = "update user_invite set invite ='' where invite! = ''";
$ Sqls = "update user_invite set invite = '". make_coupon_card (). "', addtime = '". time (). "'Where invite ='' and id = '". $ ids. "'";
Print_r ($ sqls );
// Exit;
$ Result = mysql_query ($ sqls); // execute the update
// Mysql_free_result ($ result );
}
Echo "batch generation completed ";
}
Unset ($ row );
} Else {
Echo "generated ";
}

After changing the end tag address, no error is reported, but the IDs obtained each time are the same.

Nobody...

While ($ row as $ k) try

While ($ row as $ k) try


I tried to report an error.

The younger brother posted a post for the first time .... Please do not sink ..

$ SQL = "select * from user_invite where invite ='' "; // Construct a query statement $ result_row = mysql_query ($ SQL); if (! $ Result_row) {die ("cocould not to the database
". Mysql_error ();} while ($ row = mysql_fetch_array ($ result_row, MYSQL_ASSOC) {$ ids = $ row ['id']; $ sqls = "update user_invite set invite = '". make_coupon_card (). "', addtime = '". time (). "'Where invite ='' and id = '". $ ids. "'"; $ result = mysql_query ($ sqls); // execute update} echo "batch generation completed ";

$ SQL = "select * from user_invite where invite ='' "; // Construct a query statement $ result_row = mysql_query ($ SQL); if (! $ Result_row) {die ("cocould not to the database
". Mysql_error ();} while ($ row = mysql_fetch_array ($ result_row, MYSQL_ASSOC) {$ ids = $ row ['id']; $ sqls = "update user_invite set invite = '". make_coupon_card (). "', addtime = '". time (). "'Where invite ='' and id = '". $ ids. "'"; $ result = mysql_query ($ sqls); // execute update} echo "batch generation completed ";


Thank you, Big Brother. thank you very much.

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.