在我看来,$sth-> execute(array(‘:val’=> true))成功完成,从而增加了rowCount,但$sth-> execute(array(‘:val’=> 20) ) 才不是.以下是每个阶段$sth的rowCount的状态:
$sth = $pdo->prepare("INSERT into test (var1) VALUES (:val)");
# No successful DML queries have been done with the $sth yet.
# rowCount == 0
$sth->execute(array(':val' => true));
echo $sth->rowCount() . ", ";
# rowCount increases because of a successful INSERT statement
# rowCount == 1
$sth->execute(array(':val' => 20));
echo $sth->rowCount();
# rowCount does not increase due to failed INSERT statement
# rowCount == 1
现在,让我们以相反的顺序看一下:
$sth = $pdo->prepare("INSERT into test (var1) VALUES (:val)");
# No successful DML queries have been done with the $sth yet.
# rowCount == 0
$sth->execute(array(':val' => 20));
echo $sth->rowCount();
# rowCount does not increase due to failed INSERT statement
# rowCount == 0
$sth->execute(array(':val' => true));
echo $sth->rowCount() . ", ";
# rowCount increases because of a successful INSERT statement
# rowCount == 1