note 61154 modified in function.ociparse by danbrown

From: Date: Wed, 25 Feb 2009 14:08:49 +0000
Subject: note 61154 modified in function.ociparse by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151108@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: <?php $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: <?php $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. --was-- 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. http://php.net/manual/en/function.ociparse.php

« previous php.notes (#151108) next »