I have been handling MySQL database functions within a PHP application using an object oriented style. But now I want to use a function that requires a result resource as an input variable but all I have available is a result object from the statement
$oresult = $odb->query($sql)开发者_运维知识库;
Is there a way to produce a result resource from an object oriented style database connection ($dbconn = new mysqli (...))?
Thanks you
You generally want to provide the resource to your result set (wrapper functions to encapsulate the database functions. I.e., numRows(), affectedRows(), etc.), which in turn can provide you with a record set to iterate the results if necessary.
AFAIK, both OO and Procedural styles of Mysqli do not even deal out result resources at all. The query()
and real_query()
functions and methods all immediately (or eventually lead to) return a Mysqli_result
object if a recordset is returned. There is no function or property throughout the Mysqli extension to extract the "link" from the main Mysqli
object, nor to extract the resource (per se) from the Mysqli_result
object. In fact, that $link
you see referenced throughout the procedural style examples of Mysqli is actually just a Mysqli
object.
If any function you're using calls for a "result resource", they would have to mean coming from a function of the old, regular Mysql extension. There is no way to blend Mysql and Mysqli functions and methods together. So essentially, yes, you would have to forgo Mysqli entirely in this case, and start with old-style, procedural Mysql from the very beginning.
精彩评论