New Posts  All Forums:Forum Nav:

sql and php help

post #1 of 2
Thread Starter 
I want to know how do I read in oracle sql query statements from an array and execute them using php?
HP DV5T-1000
(13 items)
 
  
CPUGraphicsRAMHard Drive
Intel Core 2 Duo P7350  Nvidia Geforce 9600M GT 512MB G.Skill 2X2GB DDR2 800Mhz 250GB Samsung SSD 840 Series 
Optical DriveOS
DVD Drive Windows 8 Pro x64 
  hide details  
Reply
HP DV5T-1000
(13 items)
 
  
CPUGraphicsRAMHard Drive
Intel Core 2 Duo P7350  Nvidia Geforce 9600M GT 512MB G.Skill 2X2GB DDR2 800Mhz 250GB Samsung SSD 840 Series 
Optical DriveOS
DVD Drive Windows 8 Pro x64 
  hide details  
Reply
post #2 of 2
Thread Starter 
This is what I got.
Concerns:
is my array and for loop implemented correctly?
should commit be inside the for loop or can I commit after all the queries are executed?
should I add break statement to break out of the for loop if cursor and result failed since it will close the connection anyway?
Code:
function execute_sql_in_oracleMulti($sqlArray) {
  putenv("ORACLE_HOME=/home/oracle/OraHome1");
  putenv("ORACLE_SID=orcl");

  $connection = oci_connect ("test", "test");
  if($connection == false){
    // failed to connect
    display_oracle_error_message(null);
    die("Failed to connect");
  }

  // Loop through sql queries array and execute them
  for ($i = 0; $i < sizeof(sqlArray); $i++) {
    $cursor = oci_parse($connection, $sqlArray[$i]);

    if ($cursor == false) {
      display_oracle_error_message($connection);
      oci_close ($connection);
      // sql failed 
      die("SQL Parsing Failed");
    }

    $result = oci_execute($cursor);

    if ($result == false) {
      display_oracle_error_message($cursor);
      oci_close ($connection);
      // sql failed 
      die("SQL execution Failed");
    }
  }

  // commit the result
  //oci_commit ($connection);

  // close the connection with oracle
  oci_close ($connection);  

  $return_array["flag"] = $result;
  $return_array["cursor"] = $cursor;

  return $return_array;
}
HP DV5T-1000
(13 items)
 
  
CPUGraphicsRAMHard Drive
Intel Core 2 Duo P7350  Nvidia Geforce 9600M GT 512MB G.Skill 2X2GB DDR2 800Mhz 250GB Samsung SSD 840 Series 
Optical DriveOS
DVD Drive Windows 8 Pro x64 
  hide details  
Reply
HP DV5T-1000
(13 items)
 
  
CPUGraphicsRAMHard Drive
Intel Core 2 Duo P7350  Nvidia Geforce 9600M GT 512MB G.Skill 2X2GB DDR2 800Mhz 250GB Samsung SSD 840 Series 
Optical DriveOS
DVD Drive Windows 8 Pro x64 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding