Heim  >  Artikel  >  Backend-Entwicklung  >  php mysql 判断update之后是否更新了的方法_PHP教程

php mysql 判断update之后是否更新了的方法_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:22:02842Durchsuche

首先我的建议是遇到问题摆渡一下,php手册翻上1001遍,问题迎刃而解。

我百度了一下,网友给的答案五花八门。

首先纠正百度来的一个错误的方法:

复制代码 代码如下:

$sql = "update table a set aname='名字' where aid=88";
$r = $conn->query($sql);
if ($r){
echo "错误以为这里就是数据做了更新,如果这个aid为88的数据不存在语句同样返回true。";
}

带where的语句即使不符合调节只要sql语句没错同样返回true,这里的true可以理解为sql语句不出错,和这样写是同样的效果:$conn->query($sql) or die("更新出错,请检查参数是否正确。");。
获取update更新的多少行的函数用:mysql_affected_rows($conn) 或者用mysqli_affected_rows($conn)

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/324760.htmlTechArticle首先我的建议是遇到问题摆渡一下,php手册翻上1001遍,问题迎刃而解。 我百度了一下,网友给的答案五花八门。 首先纠正百度来的一个错...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn