1

I am using PHP 5.6.30 with xamp. I am using oracle to connect with some database and using the fetch loop to get all its data one by one.i am using this syntax while (($data = oci_fetch_array($stid, OCI_ASSOC)) != false).

Now inside this while loop i am storing multiple insert queries with ';' separator and after 50 queries of insert, i insert that query into mysql database table using mysqli_multi_query. But i get error: Commands out of sync; you can't run this command.

sample code will be like as below:

while (($data = oci_fetch_array($stid, OCI_ASSOC)) != false)
{
 $count ++;
 $id = $data['id'];
 $name = $data['name'];

 $query .= insert into table ('id','name') values('$id','$name');

 if(count==50)
 {
   if(!mysqli_multi_query($dblink ,$insertSQL))
            {
                    echo mysqli_error($dblink);                 
                    exit;
            }   
  }
Asad
  • 11
  • 1
  • 2
    Possible duplicate of [PHP Commands Out of Sync error](http://stackoverflow.com/questions/14554517/php-commands-out-of-sync-error) – miken32 Apr 20 '17 at 05:47
  • Use prepared statements for the insert. Will be much faster. http://stackoverflow.com/documentation/php/2784/php-mysqli/11958/prepared-statements-in-mysqli#t=201704200548019482676 – miken32 Apr 20 '17 at 05:48
  • Why are you using two different APIs here? And there's missing quotes around the `$query` string, plus it will be executed multiple times (as you execute inside the loop and use multi-query). – Qirel Apr 20 '17 at 05:52
  • I have to get data from oracle database then store it in mysql table at run-time for which i am using oracle and mysqli. – Asad Apr 20 '17 at 06:01

0 Answers0