Jump to content

MySQLi identifying multiple queries on same object


munkey

Recommended Posts

Hi,

 

I recently migrated to mysqli after reading the old type is going to be phased out, but I dont understand how you identify queries:

//Assume $db is already instantiated 

$db->query("SELECT xyz FROM abc....."); //Query 1 
$db->query("SELECT efg FROM def....."); //Query 2 
$db->query("SELECT pqr FROM hij....."); //Query 3 

//Here I want to see how many rows are in query 1 and return an array for query 2

How do I tell the $db->num_rows property what query to look at as it does not have any parameters?

...and the same goes with fetching arrays and so fourth; all of these methods do not take any parameters regarding what query they are using. As far as I can see the only way would be to have one query per $db object which can't be true.

 

Thanks.

 

You do exactly the same thing as you did with the mysql_* functions: execute the query, assign the result somewhere, and look it later.

$q1 = $db->query("SELECT xyz FROM abc....."); //Query 1
$q2 = $db->query("SELECT efg FROM def....."); //Query 2
$q3 = $db->query("SELECT pqr FROM hij....."); //Query 3

echo "query 1 returned {$q1->num_rows} rows\n";
echo "first row of query 2 is " . implode(", ", $q2->fetch_array()), "\n";
echo "query 3 has {$q3->field_count} columns\n";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.