輸入待尋字串
  <?php
  require("http://php.wilson.gs");  // 回首頁
  echo "http://php.wilson.gs/bible/function.php : 函式:mysql_fetch_object()";


函式:mysql_fetch_object()


mysql_fetch_object

傳回物件資料。

語法: object mysql_fetch_object(int result, int [result_typ]);

傳回值: 物件

函式種類: 資料庫功能

內容說明

本函式用來將查詢結果 result 拆到物件變數中。使用方法和 mysql_fetch_array() 幾乎相同,不同的地方在於本函式傳回資料是物件而不是陣列。若 result 沒有資料,則傳回 false 值。另外值得注意的地方是,取回的物件資料的索引只能是文字而不能用數字,這是因為物件的特性。物件資料的特性中所有的屬性 (property) 名稱都不能是數字,因此只好乖乖使用文字字串當索引了。參數 result_typ是一個常數值,有以下幾種常數 MYSQL_ASSOC、MYSQL_NUM 與 MYSQL_BOTH。關於速度方面,本函式的處理速度幾乎和 mysql_fetch_row()mysql_fetch_array() 二函式差不多,要用哪個函式還是看使用的需求決定。

使用範例

下面的例子示範如使用傳回的物件。

<?php 
mysql_connect
($host,$user,$password);
$result mysql_db_query("MyDatabase","select * from test");
while(
$row mysql_fetch_object($result)) {
    echo 
$row->user_id;
    echo 
$row->fullname;
}
mysql_free_result($result);
?>

參考

mysql_fetch_array()  mysql_fetch_row()  


[ 上一頁 /bible/function.php 下一頁 ]



本站置於 NEC BIGLOBE 地球村網際網路  echo "Copyright © 1999-2001, Wilson Peng";  //隱私權保護政策
  mail("wilson@biglobe.net.tw", "Feedback", $message);
  ?>