Home > Backend Development > PHP Tutorial > php批量更新数据库,但是显示内存不足,改过也不行,求大神

php批量更新数据库,但是显示内存不足,改过也不行,求大神

WBOY
Release: 2016-06-23 13:29:44
Original
964 people have browsed it

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=''";//构建查询语句$result_row=mysql_query($sql);if(!$result_row){die("could not to the database</br>".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);//执行更新	//unset($value);	}	echo "已经批量生成完成";	}else{	echo "已经生成过了";		}
Copy after login


回复讨论(解决方案)

while($row){
....
}
你这不是死循环吗?

while($row){
....
}
你这不是死循环吗?


在下新手,请问大神怎么改进啊?还望不惜赐教

$sql="select * from user_invite where invite=''";//构建查询语句
$result_row=mysql_query($sql);

if(!$result_row)
{
die("could 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);//执行更新
//mysql_free_result($result);
}
echo "已经批量生成完成";
}
unset($row);
}else{
echo "已经生成过了";
}

改了下结束标签地址,现在是不报错了,但是每次取出来的id都是一样的

没人吗。。。

while($row as $k) 试试

while($row as $k) 试试


试过了报错呢。

小弟第一次发帖啊。。。。求别沉。。

$sql="select * from user_invite where invite=''";//构建查询语句$result_row=mysql_query($sql);if(!$result_row){  die("could not to the database</br>".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);//执行更新}echo "已经批量生成完成";
Copy after login
Copy after login

$sql="select * from user_invite where invite=''";//构建查询语句$result_row=mysql_query($sql);if(!$result_row){  die("could not to the database</br>".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);//执行更新}echo "已经批量生成完成";
Copy after login
Copy after login


谢谢大哥,小弟真心万分感谢。
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template