PHP mysql_fetch_object() 函数
定义和用法
mysql_fetch_object() 函数从结果集(记录集)中取得一行作为对象。
若成功的话,本函数从 mysql_query() 获得一行,并返回一个对象。如果失败或没有更多的行,则返回 false。
Sintassi
mysql_fetch_object(data)
Parametro | Descrizione |
---|---|
data | Obbligatorio. Puntatore ai dati da utilizzare. Il puntatore ai dati è stato mysql_query() Risultato restituito. |
Suggerimenti e note
Nota:Ogni successiva chiamata a mysql_fetch_object() restituisce la riga successiva del set di record.
Nota:mysql_fetch_object() e mysql_fetch_array() Simile, con una piccola differenza - restituisce un oggetto invece di un array. Indirettamente, significa che è possibile accedere all'array tramite il nome del campo invece dell'offset.
Esempio
<?php $con = mysql_connect("localhost", "peter", "abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db("test_db",$con); $sql = "SELECT * from Person"; $result = mysql_query($sql,$con); while ($row = mysql_fetch_object($result)) { echo $row->FirstName . "<br />"; } mysql_close($con); ?>
Output:
John George Thomas