• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php mysql insert into while 不测终止

php 搞代码 3年前 (2022-01-24) 16次浏览 已收录 0个评论

php mysql insert into while 意外终止

PHP code

<!---ecms 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>";}}

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

——解决方案——————–
。。
像你这种问题,肯定是要在cli模式下跑单条sql处理才靠谱啊!!!
至不济也要先把数据导出,然后导入,而不是这样做啊
参见select into
——解决方案——————–
有几个问题需要注意排除:
1、php超时
2、web服务器超时
3、特殊字符未转义
4、count($array) < 5

算法上可考虑:
每千条组装成多个VALUE的INSERT语句后插入
以分页方式逐段插入

直接使用SQL指令完成,而不经php转手
$sql =<<< 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),’$sep

本文来*源gaodai^.ma#com搞#代!码网
搞gaodaima代码

r’,-1)
, substring_index(substring_index(cate,’$sepr’,4),’$sepr’,-1)
, substring_index(substring_index(cate,’$sepr’,5),’$sepr’,-1)
FROM upcm
SQL;


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php mysql insert into while 不测终止
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址