Jump to content

mysqli question on types it returns


johnmerlino

Recommended Posts

Hey all,

 

In this basic example:

 

$db = new mysqli('localhost','root','pass','schools');
$query = "select * from schools where ".$type." like '%" . $term . "%'";
$result = $db->query($query);

 

Let's say the $query local variable holds a string constructed of a mysql query that gets passed as argument to query method of mysqli instance. What exactly is the return value of query()? What is the type that is stored in the variable $result?  I heard it called a "result object". Is a result object just a pointer to a mysql resource or something?

 

Here:

$num_results = $result->num_rows;
for($i=0; $i < $num_results; $i++){
$row = $result->fetch_assoc();
}

 

$result->fetch_assoc();

returns a record resource as an array

 

$row = $result->fetch_object(); 

returns a record resource as an object;

 

which is preferred? Can I work with array functions on the latter?

 

thanks for response

Link to comment
Share on other sites

Is a result object just a pointer to a mysql resource or something?

 

Exactly correct, it's just a pointer or reference to a MySQL result set.

 

which is preferred? Can I work with array functions on the latter?

 

If you're generally writing OOP then fetch_object() is preferred or more appropriate.

 

Array functions on objects? What have you got in mind?

 

 

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.