Last active
October 7, 2020 15:51
-
-
Save crevillo/bd7b75d4a809a7edeb9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $host="localhost"; | |
| $root="root"; | |
| $root_password="***************"; | |
| $dbh = new PDO("mysql:host=$host", $root, $root_password); | |
| $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
| $dbh->setAttribute(PDO::MYSQL_ATTR_FOUND_ROWS, TRUE); | |
| $dbh->query("CREATE DATABASE IF NOT EXISTS `newdb`"); | |
| $dbh->query("use newdb"); | |
| $dbh->query("CREATE TABLE IF NOT EXISTS tabla (id INT PRIMARY KEY, value INT)"); | |
| $statement = $dbh->prepare("INSERT ignore INTO tabla VALUES ( 1, 10 )"); | |
| $statement->execute(); | |
| $statement = $dbh->prepare("UPDATE tabla SET value = 20 where id = 1"); | |
| $statement->execute(); | |
| print "rowCount For First update: " . $statement->rowCount() . "\n"; | |
| $statement = $dbh->prepare("UPDATE tabla SET value = 20 where id = 1"); | |
| $statement->execute(); | |
| print "rowCount For First update: " . $statement->rowCount() . "\n"; | |
| $dbh->query( "DROP DATABASE newdb" ); | |
| /** without MYSQL_ATTR_FOUND_ROWS" **/ | |
| $dbh = new PDO("mysql:host=$host", $root, $root_password); | |
| $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
| $dbh->query("CREATE DATABASE IF NOT EXISTS `newdb`"); | |
| $dbh->query("use newdb"); | |
| $dbh->query("CREATE TABLE IF NOT EXISTS tabla (id INT PRIMARY KEY, value INT)"); | |
| $statement = $dbh->prepare("INSERT ignore INTO tabla VALUES ( 1, 10 )"); | |
| $statement->execute(); | |
| $statement = $dbh->prepare("UPDATE tabla SET value = 20 where id = 1"); | |
| $statement->execute(); | |
| print "rowCount For First update: " . $statement->rowCount() . "\n"; | |
| $statement = $dbh->prepare("UPDATE tabla SET value = 20 where id = 1"); | |
| $statement->execute(); | |
| print "rowCount For First update: " . $statement->rowCount() . "\n"; | |
| $dbh->query( "DROP DATABASE newdb" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rowCount For First update: 1
rowCount For First update: 0
rowCount For First update: 1
rowCount For First update: 0
Is this wrong? I think it should be 1 1 1 0