PHP uses mysql_fetch_object to obtain the object set from the query results
This article mainly introduces how PHP uses mysql_fetch_object to obtain the object set from the query result. The example shows the php operation mysql_fetch_object to query the database. It is very useful. For more information, see
This example describes how PHP uses mysql_fetch_object to obtain an object set from the query results. Share it with you for your reference. The specific analysis is as follows:
The mysql_fetch_object function is used to extract the result row from a MySQL result set as an array of objectiative.
Mysql_fetch_object Syntax:
?
1 |
Array mysql_fetch_object (resource $ Result_Set) |
The Result_Set handle returns a mysql_query query result set.
If the execution is successful, return the object that contains all data rows. If the execution fails, return the bool value.
The following is the Demo code:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<? Php $ UserName = 'abc '; $ Password = '000000 '; $ DbHandle = mysql_connect ('localhost', $ UserName, $ Password ); If (! $ DbHandle ){ Die 'no database connection cocould be established .'; } $ DBName = 'wdb; If (! Mysql_select_db ($ DBName, $ DbHandle )){ Die 'database cocould not be selected .'; } $ Query = "select isbn, Title, Author FROM articles "; $ Articles = mysql_query ($ Query, $ DbHandle )); While ($ Row = mysql_fetch_object ($ articles )){ Echo "ISBN = $ Row-> ISBN <br/> \ n "; Echo "Title = $ Row-> Title <br/> \ n "; Echo "Author = $ Row-> Author <br/> \ n "; } ?> |
I hope this article will help you with php programming.