Forked from crevillo/pdo PDO::MYSQL_ATTR_FOUND_ROWS test.php
Created
May 24, 2018 21:34
-
-
Save newacorn/b49d990185667de8703180f382bf4b80 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