php mysql insert into while 不測終止

來源:互聯網
上載者:User
php mysql insert into while 意外終止
PHP code
$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)擷取查詢的結果,逐條處理,處理後寫進一個新的表裡面,但是每次執行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),'$sepr',-1)
, substring_index(substring_index(cate,'$sepr',4),'$sepr',-1)
, substring_index(substring_index(cate,'$sepr',5),'$sepr',-1)
FROM upcm
SQL;
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.