note 61154 added to function.ociparse
| From: | php-general at lists dot php dot net | Date: | Fri, 27 Jan 2006 00:05:34 +0000 |
| Subject: | note 61154 added to function.ociparse | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102517@lists.php.net to get a copy of this message | ||
one of the most things that is done wrong with oracle is the following.
Cosider:
-------------------------------------------------------------------
$dbh = ocilogon('user', 'pass', 'db');
for ($i = 0; $i<=10; $i++) {
$sth = ociparse($dbh, 'SELECT * FROM T WHERE x = :x');
ocibindbyname($sth, ':x', $i, -1);
ociexecute($sth, OCI_DEFAULT);
if (ocifetchrow($sth, $row, OCI_ASSOC+OCI_RETURN_NULLS)) {
var_dump($row);
}
}
ocilogoff($dbh);
-------------------------------------------------------------------
Problem here is, that you parse the same statement over and over and that'll cost ressources
and will introduce many wait events. This problem will increase exponentially with the number of
users using your system. That's one of the things besides not using bind variables that will
prevent your application from scaling well.
The right approach:
-------------------------------------------------------------------
$dbh = ocilogon('user', 'pass', 'db');
$sth = ociparse($dbh, 'SELECT * FROM T WHERE x = :x');
for ($i = 0; $i<=10; $i++) {
ocibindbyname($sth, ':x', $i, -1);
ociexecute($sth, OCI_DEFAULT);
if (ocifetchrow($sth, $row, OCI_ASSOC+OCI_RETURN_NULLS)) {
var_dump($row);
}
}
ocilogoff($dbh);
------------------------------------------------------------------
Now we are parsing the statement once and using it as often as possible.
When your using Oracle, create proper indexes, use bind variables and parse once and execute often.
Not doing so will get you into trouble when more than a few users are working with your application
simultaneously.
----
Server IP: 217.160.72.57
Probable Submitter: 84.147.211.124
----
Manual Page -- http://www.php.net/manual/en/function.ociparse.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61154
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61154&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61154&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61154&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61154&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61154&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61154&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61154&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61154&report=yes
Search -- http://master.php.net/manage/user-notes.php