dragonpeng200811111 2015-02-18 19:00
浏览 410

警告:mysql_affected_rows()期望参数1是资源但没有错误[重复]

$sql2 = "INSERT IGNORE INTO table (word) VALUES ('test')"; 
$result2 = mysql_query($sql2);
if (!$result2){
    throw new My_Db_Exception('Database error: ' . mysql_error());
} else {
    echo "OK";  
}
$affected_rows = mysql_affected_rows($result2);

I know there are a ton of posts on this topic, but I am truly stumped on this. For some reason my query returns

Warning: mysql_affected_rows() expects parameter 1 to be resource, boolean given

As you can see below I am running an if statement to determine what the error is, but this statement returns "OK" as if there is no issue.

The warning message only comes when I want to use a mysql_num_rows or mysql_affected_rows

I know that mysql_affected_rows is what I really want for my INSERT IGNORE, but I tested out mysql_num_rows for kicks and returns same error.

Even if I run this exact query in phpmyadmin I get

phpmyadmin error

What am I not seeing? I am getting no errors except for the Warning: mysql_affected_rows() expects parameter 1 to be resource

UPDATE SOLVED

It was due to mysql_affected_rows was grabbing a previous connection to a DB so I had to pass the query as $affected_rows = mysql_affected_rows(); with no connection specified. Since the connection it was using was passing TRUE that is the reason no errors were being thrown.

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 MATLAB动图的问题
    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名