如何在此显示受影响的行数:
$sql = $conn->prepare ("UPDATE countries SET country=:country");
$sql->bindValue(":country", "blablaa");
$sql->execute();
Run Code Online (Sandbox Code Playgroud)
如何显示最后插入的ID:
$sql = $conn->prepare ("INSERT INTO countries (country) VALUES (:country)");
$sql->bindValue(":country", "test");
$sql->execute();
echo $sql->lastInsertId(); // id of last inserted
Run Code Online (Sandbox Code Playgroud)
我试过,但是收到一个错误调用未定义的方法 PDO::lastInsertId()
EmR*_*228 12
我想这可以帮到你:
PDOStatement对象:: rowCount时()
返回由相应PDOStatement对象执行的最后一个DELETE,INSERT或UPDATE语句影响的行数. http://php.net/manual/en/pdostatement.rowcount.php
$sql->lastInsertId();
Run Code Online (Sandbox Code Playgroud)
需要更换
$dbh->lastInsertId();
Run Code Online (Sandbox Code Playgroud)
$ dbh是你的PDO对象.
有关更多信息,请参见此处
exec返回受影响的行数,execute仅返回true或false值.