Home > Backend Development > PHP Tutorial > php mysql insert into while 不测终止

php mysql insert into while 不测终止

WBOY
Release: 2016-06-13 13:09:54
Original
795 people have browsed it

php mysql insert into while 意外终止

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->$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<br>";
}
}
Copy after login


mysql_fetch_row($result)获取查询的结果,逐条处理,处理后写进一个新的表里面,但是每次执行while循环总是还没执行完程序就终止了,没有处理完数据,把insert into 换成printf(“**”);代替插入操作,会将程序正确执行完毕,而且每次运行程序插入的条数不一,有时多有时少,请问大侠们什么情况这是,苦恼啊..

------解决方案--------------------
。。
像你这种问题,肯定是要在cli模式下跑单条sql处理才靠谱啊!!!
至不济也要先把数据导出,然后导入,而不是这样做啊
参见select into
------解决方案--------------------
有几个问题需要注意排除:
1、php超时
2、web服务器超时
3、特殊字符未转义
4、count($array)
算法上可考虑:
每千条组装成多个VALUE的INSERT语句后插入
以分页方式逐段插入

直接使用SQL指令完成,而不经php转手
$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;
Related labels:
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