How can I display the numbers of affected rows in this:
$sql = $conn->prepare ("UPDATE countries SET country=:country");
$sql->bindValue(":country", "blablaa");
$sql->execute();
And how can I show the last inserted ID with this:
$sql = $conn->prepare ("INSERT INTO countries (country) VALUES (:country)");
$sql->bindValue(":country", "test");
$sql->execute();
echo $sql->lastInsertId(); // id of last inserted
I tried, but am receiving an error call to undefined method PDO::lastInsertId()
$sql->lastInsertId();
Needs to be replaced with
$dbh->lastInsertId();
Where $dbh is your PDO object.
See here for more information.
exec
returns the number of affected rows, execute
only returns a true or false value.
I think this can help you:
PDOStatement::rowCount()
returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object. http://php.net/manual/en/pdostatement.rowcount.php