Jump to content

MySQLi identifying multiple queries on same object


munkey
Go to solution Solved by requinix,

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.

 

Edited by munkey
Link to comment
Share on other sites

  • Solution

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";
Edited by requinix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.