note 114616 added to pdo.prepare
| From: | bg at enativ dot com | Date: | Wed, 12 Mar 2014 15:11:31 +0000 |
| Subject: | note 114616 added to pdo.prepare | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198874@lists.php.net to get a copy of this message | ||
if you run queries in a loop, don't include $pdo->prepare() inside the loop, it will save
you some resources (and time).
prepare statement inside loop:
for($i=0; $i<1000; $i++) {
$rs = $pdo->prepare("SELECT
id FROM admins WHERE
groupID = :groupID AND id <> :id");
$rs->execute([':groupID' => $group, ':id' => $id]);
}
// took 0.066626071929932 microseconds
prepare statement outside loop:
$rs = $pdo->prepare("SELECT id FROM admins WHERE
groupID = :groupID AND id <> :id");
for($i=0; $i<1000; $i++) {
$rs->execute([':groupID' => $group, ':id' => $id]);
}
// took 0.064448118209839 microseconds
for 1,000 (simple) queries it took 0.002 microseconds less.
not much, but it worth mention.
----
Server IP: 212.199.163.163
Probable Submitter: 62.219.134.104
----
Manual Page -- http://php.net/manual/en/pdo.prepare.php
Edit -- https://master.php.net/note/edit/114616
Del: integrated -- https://master.php.net/note/delete/114616/integrated
Del: useless -- https://master.php.net/note/delete/114616/useless
Del: bad code -- https://master.php.net/note/delete/114616/bad+code
Del: spam -- https://master.php.net/note/delete/114616/spam
Del: non-english -- https://master.php.net/note/delete/114616/non-english
Del: in docs -- https://master.php.net/note/delete/114616/in+docs
Del: other reasons-- https://master.php.net/note/delete/114616
Reject -- https://master.php.net/note/reject/114616
Search -- https://master.php.net/manage/user-notes.php