0

I am getting exception while calling a stored procedure in a for loop.here is my code

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);

$total      = 0;
$error      = 0; 
$trimmed = explode("\n",file_get_contents($fileName));

for ($i = 0; $i < 2; $i++) {    
    $qry_ins = "call sampleProcedureTest();";
     try {
         mysql_query($qry_ins) or throw_ex(mysql_error());
         $total++;
     } catch(Exception $e) {
         echo $e;
         echo  $qry_ins;
         echo "</br></br>";
         $error++;
     }
}


I have searched but didn't find any good reason and solution
NOTE: When I remove the loop then it works fine.But My need is to call in a loop
Guide me please regarding this

EDIT # 1: Here is the procedure

BEGIN
DECLARE uid VARCHAR(10) DEFAULT "0000";
SELECT SUBSTRING(MD5(RAND()) FROM 1 FOR 4) AS passwordStrin into uid FROM NO WHERE uid not in (Select ID from UIDLIST WHERE ID=uid);

    INSERT IGNORE INTO UIDLIST values(uid);

    select REPLACE(MSG,'URL',CONCAT('http://abc.org/?uid=',uid)) as message,SOURCE as sender,MODE as mode,uid  as uniqueid from testDB _MESSAGE;

    select REPLACE(MSG,'URL',CONCAT('http://abc.org/?uid=',uid)) as message,SOURCE as sender,MODE as mode,uid  as uniqueid from testDB_MESSAGE;
END
Ahmed Siouani
  • 13,701
  • 12
  • 61
  • 72
Despicable
  • 3,797
  • 3
  • 24
  • 42

1 Answers1

0

You need to remove the select statement from your procedure (in case they are not useful for you).The problem is that procedure is returning you data so thats why it is problematic when you call it from the same script in a loop
also see Calling Stored Procedure in foreach loop - only first executed
Another solution is (which is not recommended) in case you still want to place select statments in procedure that use need to connect to db , call procedure , release connection in every iteration.

Community
  • 1
  • 1
Freak
  • 6,786
  • 5
  • 36
  • 54