Skip to content

Instantly share code, notes, and snippets.

Created August 30, 2012 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3540454 to your computer and use it in GitHub Desktop.
Save anonymous/3540454 to your computer and use it in GitHub Desktop.
pdo update
<?php
$dbh = new PDO('mysql:host=localhost;dbname=testacc', 'root', '');
$dbh->setAttribute(PDO::ATTR_AUTOCOMMIT,FALSE);
$withoutPrepare = 0;
$withprepare = 0;
$preparewithoutbind = 0;
$times =2000 ;
for($i=0; $i<=$times;$i++){
//with query + quote
$time_start = microtime(true);
$arrParams[0] = "sebbbbba" ;
$arrParams[1] = "1" ;
$dbh->beginTransaction();
$result = $dbh->query("update `testacc`.`application` set name='". $arrParams[0] .$i."'
WHERE `application`.`ID` = ".
$dbh->quote($arrParams[1] ) );
$dbh->commit();
$time_end = microtime(true);
$time = $time_end - $time_start;
$withoutPrepare+=$time ;
////////////////////////////////////////////////////////////////////////////////////////////
//with prepare with bind
$time_start = microtime(true);
$dbh->beginTransaction();
$result = $dbh->prepare("update `testacc`.`application` set name=? WHERE `application`.`ID` = ? ") ;
$result->execute(array("sebbbb".$i,"1''"));
$dbh->commit();
$time_end = microtime(true);
$time = $time_end - $time_start;
$withprepare+=$time ;
////////////////////////////////////////////////////////////////////////////////////////////
//// with prepare wihout bind
$time_start = microtime(true);
$arrParams[0] = "sesesddqs" ;
$arrParams[1] = "1" ;
$dbh->beginTransaction();
$result = $dbh->prepare("update `testacc`.`application`
set name='{$arrParams[0]}' WHERE `application`.`ID` = '{$arrParams[1]}' ") ;
$result->execute();
$dbh->commit();
$time_end = microtime(true);
$time = $time_end - $time_start;
$preparewithoutbind+=$time ;
////////////////////////////////////////////////////////////////////////////////////////////
}
echo "with query + quote : ".$withoutPrepare/$times ;
echo "<br> with prepare wihout bind : ".$preparewithoutbind/$times ;
echo "<br> with prepare with bind: ".$withprepare/$times ;
/////////////////////////////
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment