Online Shopping : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

8 of 52 people (15%) answered Yes
Recently 1 of 10 people (10%) answered Yes

Entry

Can i send multiple queries in one function call? ie $query = "create table...; insert into..."

Mar 29th, 2002 21:20
Jeff, Narendra Jain, ken easson,


I am not sure why you might want to send to db queries at the same 
time, but I know that it helps to make websites more efficent if you 
reduce the amount of talking between PHP and the database. You might 
consider using a stored procedure if your DB provides for them, this 
way you can have full error checking and all you have to do is issue 
the one statement.
Yes, you can execute multiple queries in a single function.
However, it is adviseable to check that the previous query completed
successfully or not. viz.
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$l_qry= " select first_name from usermaster ".
        " where active_ok = 'Y' "
$result = mysql_query($l_qry);
if ($result) {
   $l_qry=" select last_name from usermaster ".
          " where active_ok = 'Y' "
   $result = mysql_query($l_qry);
   if ($result) {
   } else {
      echo "Query error:".$l_qry;
   }
} else {
   echo "Query error:".$l_qry;
}