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
https://forums.phpfreaks.com/topic/244649-mysqli-question-on-types-it-returns/
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?

 

 

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.