dongnan1989 2012-07-18 14:13
浏览 41

MySQL更新没有更新所有行(使用php)

I am trying to update my values and something weird is happening, MySQL seems to be updating rows out of its own free will. Here is what I do

UPDATE accountsTable SET Status = 'TerminatedProfile' WHERE id IN (1,2,3)

And it updates either one or two rows not all 3, even if I run the code multiple times. And if I take this query and run it through phpmyadmin it works fine. Is there something wrong with php's mysql implementation or what?

I am using

mysql_connect("$host", "$user", "$password")or die("cannot connect"); 
mysql_select_db("$db")or die("cannot select DB"); 
mysql_query($query2);

Update: I was running it on Joomla and perhaps it had something to do with session because one of the rows I was trying to update was on the admin user I was logged in with. Thanks for the responses specially MikeB.

  • 写回答

1条回答 默认 最新

  • dreamMyDream2014 2012-07-18 14:48
    关注

    It's difficult to know what is going on without the full code or where $query2 has being applied.

    But you can try to update these rows not using a list. Try:

    UPDATE accountsTable SET Status = 'TerminatedProfile' WHERE id = 1 AND id = 2 AND id = 3
    

    It's just to make sure the problem is or not where $query2 is.

    You can also try to run this query right on mysql console, and see what happens. If works, probably the error is in how you're doing it.

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?