Created
August 30, 2012 20:44
-
-
Save anonymous/3540454 to your computer and use it in GitHub Desktop.
pdo update
This file contains 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 | |
$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