ฟังก์ชั่น mysql_fetch_object()
ความหมายของฟังก์ชั่นและการใช้งาน
การคืนค่าข้อมูลของ result ในแถวที่ชี้อยู่ แล้วเก็บไว้ที่ object และเลื่อนไปตัวชี้ให้ชี้ไปยังตำแหน่งถัดไป โดยจะคืนค่า false กรณีที่เกิดความผิดพลาด ด้วยฟังก์ชั่น mysql_fetch_object()
รูปแบบการเขียน (Syntax)
object mysql_fetch_object ( resource $result [, string $class_name [, array $params ]] )
ตัวอย่างที่ 1
<?php
mysql_connect("hostname", "user", "password");
mysql_select_db("mydb");
$result = mysql_query("select * from mytable");
while ($row = mysql_fetch_object($result)) {
echo $row->user_id;
echo $row->fullname;
}
mysql_free_result($result);
?>
ตัวอย่างที่ 2
<?php
class foo {
public $name;
}
mysql_connect("hostname", "user", "password");
mysql_select_db("mydb");
$result = mysql_query("select name from mytable limit 1");
$obj = mysql_fetch_object($result, 'foo');
var_dump($obj);
?>