sql - Execute multiple queries in a single database connection using oracle 10g and php -


i want run multiple sql queries in single database connection using oracle 10g , php. here every sql query queries have create database connection. there way run multiple sql queries in single database connection or have fetch data way only? because when have run 50 queries, have write 50 times below.

<?php include("mydb.php"); // run query  $sql6 = "select * dat to_char(wd,'dd/mm')='19/08'"; $stid6=oci_parse($conn, $sql6); // set array $arr6 = array(); if(!$stid6){ $e=oci_error($conn); trigger_error(htmlentities($e[message],ent_quotes),e_user_error); }  $r6=oci_execute($stid6);  if(!$r6){ $e=oci_error($stid6); trigger_error(htmlentities($e[message],ent_quotes),e_user_error); }  // through query while($row = oci_fetch_array($stid6,oci_assoc)){    // add each row returned array   $arr6[] = array(($row['wd']) , (float)$row['data']);  }  oci_free_statement($stid6); oci_close($conn); ?>  <?php include("mydb.php"); // run query  $sql7 = "select * dat to_char(wd,'dd/mm')='11/03'"; $stid7 = oci_parse($conn, $sql7); // set array $arr7 = array(); if(!$stid7){ $e=oci_error($conn); trigger_error(htmlentities($e[message],ent_quotes),e_user_error); }  $r7=oci_execute($stid7);  if(!$r7){ $e=oci_error($stid7); trigger_error(htmlentities($e[message],ent_quotes),e_user_error); }  // through query while($row = oci_fetch_array($stid7,oci_assoc)){    // add each row returned array   $arr7[] = array(($row['wd'])) , (float)$row['data']);  }   oci_free_statement($stid7); oci_close($conn); ?> ................ ................ 

*pardon me, forgot mention have store day-wise data in different array. mean 11/03's data store in arr1 , 19/08's data stored in arr2. not in same array.

(this should comment, bit long)

i don't want disparaging here, question alarming naive - so should closed off-topic.

your code exhibits lack of understanding modular programming , variable scope. these should covered day 2 of programming-from-scratch course. oddly includes more sophisticated php specific programming, apalling sql - looks else wrote code quick hack , trying extend capabilities.

that using oracle database, raises sorts of questions why attempting (oracle expensive; how can afford not afford provision skills need?)

the solution problem as have described it re-implement script function takes oci connection , sql statement parameters, simply....

<?php include("mydb.php");  $queries=array(     "select * dat to_char(wd,'dd/mm')='11/03'",     "select * dat to_char(wd,'dd/mm')='19/08'" ); foreach ($queries $sql) {    run_qry($sql, $conn); } oci_close($conn); exit;  function run_query($sql, $conn) {    $stid=oci_parse($conn, $sql);    // set array    $arr = array();    if(!$stid){    $e=oci_error($conn);       trigger_error(htmlentities($e[message],ent_quotes),e_user_error);    }    ...    oci_free_statement($stid);    return $arr; } 

however since 2 example queries have same structure, there other ways results of multiple queries - merging sql states single select using or or union, using parameterized queries. since code you've shown throws away results hard how should approach task.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -