johnmerlino Posted August 12, 2011 Share Posted August 12, 2011 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 More sharing options...
the182guy Posted August 12, 2011 Share Posted August 12, 2011 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 https://forums.phpfreaks.com/topic/244649-mysqli-question-on-types-it-returns/#findComment-1256619 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.