本文實例講述了PHP使用mysql_fetch_object從查詢結果中獲取對象集的方法。分享給大家供大家參考。具體分析如下:
mysql_fetch_object函數用於,提取結果行從一個MySQL的結果集作為objectiative數組。
mysql_fetch_object語法:
array mysql_fetch_object (resource $Result_Set)
Result_Set句柄返回一個mysql_query查詢結果集。
如果執行成功返回包含了所有數據行的object,如果失敗則返回bool值
下面是演示代碼:
<?php $UserName = 'abc'; $Password = '1234'; $DbHandle = mysql_connect ('localhost', $UserName, $Password); if (!$DbHandle) { die 'No database connection could be established.'; } $DBName = 'w3db; if (!mysql_select_db ($DBName, $DbHandle)) { die 'Database could 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"; } ?>
希望本文所述對大家的php程序設計有所幫助。