Skip to content

Instantly share code, notes, and snippets.

@crevillo
Last active October 7, 2020 15:51
Show Gist options
  • Save crevillo/bd7b75d4a809a7edeb9c to your computer and use it in GitHub Desktop.
Save crevillo/bd7b75d4a809a7edeb9c to your computer and use it in GitHub Desktop.

Revisions

  1. crevillo renamed this gist Sep 10, 2014. 1 changed file with 0 additions and 0 deletions.
  2. crevillo renamed this gist Sep 10, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. crevillo revised this gist Sep 10, 2014. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -25,11 +25,6 @@

    $dbh->query( "DROP DATABASE newdb" );

    $host="localhost";

    $root="root";
    $root_password="2048";


    /** without MYSQL_ATTR_FOUND_ROWS" **/
    $dbh = new PDO("mysql:host=$host", $root, $root_password);
  4. crevillo created this gist Sep 10, 2014.
    51 changes: 51 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    <?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" );

    $host="localhost";

    $root="root";
    $root_password="2048";


    /** 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" );