note 108652 added to function.oci-bind-by-name

From: Date: Tue, 15 May 2012 04:48:15 +0000
Subject: note 108652 added to function.oci-bind-by-name
Groups: php.notes 
Request: Send a blank email to php-notes+get-187982@lists.php.net to get a copy of this message
I unfortunately used the code below for a data synchronize process and ended up in big trouble: <?php /* cache data from other source */ $u=oci_parse($con,"UPDATE....WHERE id=:b_id"); oci_bind_by_name($u,":b_id",$id,-1,SQLT_INT); //bind value... $i=oci_parse($con,"INSERT INTO..."); oci_bind_by_name($i,":b_id",$id,-1,SQLT_INT); //bind value using the same variables while(/*read data from cache*/) { oci_execute($u,OCI_NO_AUTO_COMMIT); if(oci_num_rows($u)<=0) oci_execute($i,OCI_NO_AUTO_COMMIT); } oci_commit($con); ?> Although in fact the $i statement is never executed, after commit, I found that ALL data are copied as the last row of cached source. I then spent the next hour rebuilding the whole table. So it seems it's not OK to bind the same variables to two (or more) statements, even if just one statement is actually executed. I guess this is not a good practice to even think of using more than one statement each time, as no one has said it before, but I think this doesn't clearly violate the "be careful for address binding" rule, so it's still worth to be noted here to prevent some headache. ---- Server IP: 69.147.83.197 Probable Submitter: 203.98.176.247 ---- Manual Page -- http://www.php.net/manual/en/function.oci-bind-by-name.php Edit -- https://master.php.net/note/edit/108652 Del: integrated -- https://master.php.net/note/delete/108652/integrated Del: useless -- https://master.php.net/note/delete/108652/useless Del: bad code -- https://master.php.net/note/delete/108652/bad+code Del: spam -- https://master.php.net/note/delete/108652/spam Del: non-english -- https://master.php.net/note/delete/108652/non-english Del: in docs -- https://master.php.net/note/delete/108652/in+docs Del: other reasons-- https://master.php.net/note/delete/108652 Reject -- https://master.php.net/note/reject/108652 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#187982) next »