成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? PHP:MySQL函數mysql_fetch_object()的用法
全站頭部文字 我要出現在這里
PHP:MySQL函數mysql_fetch_object()的用法 703 2023-12-14   

mysql_fetch_object

(PHP 4, PHP 5)

mysql_fetch_object — 從結果集中取得一行作為對象

說明

object mysql_fetch_object ( resource $result )

返回根據所取得的行生成的對象,如果沒有更多行則返回 FALSE。

mysql_fetch_object() 和 mysql_fetch_array() 類似,只有一點區別 - 返回一個對象而不是數組。間接地也意味著只能通過字段名來訪問數組,而不是偏移量(數字是合法的屬性名)。

Note: 此函數返回的字段名大小寫敏感。

<?php

/* this is valid */
echo $row->field;
/* this is invalid */
echo $row->0;

?>

速度上,本函數和 mysql_fetch_array() 一樣,也幾乎和 mysql_fetch_row() 一樣快(差別很不明顯)。

Example #1 mysql_fetch_object() 例子

<?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);
?>

參見 mysql_fetch_array(),mysql_fetch_assoc() 和 mysql_fetch_row()。

參數

result

resource 型的結果集。此結果集來自對 mysql_query() 的調用。

class_name

The name of the class to instantiate, set the properties of and return. If not specified, a stdClass object is returned.

params

An optional array of parameters to pass to the constructor for class_name objects.

返回值

Returns an object with string properties that correspond to the fetched row, or FALSE if there are no more rows.

更新日志

版本 說明 5.0.0 Added the ability to return as a different object.

范例

Example #2 mysql_fetch_object() example

<?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);
?>

Example #3 mysql_fetch_object() example

<?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);
?>

注釋

Note: Performance

Speed-wise, the function is identical to mysql_fetch_array(), and almost as quick as mysql_fetch_row() (the difference is insignificant).

Note:

mysql_fetch_object() is similar to mysql_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).

Note: 此函數返回的字段名大小寫敏感。

Note: 此函數將 NULL 字段設置為 PHP NULL 值。

參見

mysql_fetch_array() - 從結果集中取得一行作為關聯數組,或數字數組,或二者兼有 mysql_fetch_assoc() - 從結果集中取得一行作為關聯數組 mysql_fetch_row() - 從結果集中取得一行作為枚舉數組 mysql_data_seek() - 移動內部結果的指針 mysql_query() - 發送一條 MySQL 查詢


主站蜘蛛池模板: 直播一级片| 香港之夜完整版在线观看免费| 小猫叫声吸引猫mp3| 闪电11人| 琅琊榜豆瓣评分| 故乡原风景纯音乐 陶笛| gayvideos| 心跳源计划演员表| 美女中刀| 回到十八岁| 张天爱三级露全乳hd电影| 最美表演| 贝蒂的启蒙| 李采潭全部电影在线观看| 唐砖演员表| 搜狐搜狐| 小学生大课间武术| 王宝强电影全部作品| 夜魔3| 四年级第一二单元测试卷答案| 处女膜视频| 信我者无需多言,不信我者| 郑志昊| 我的年轻小姨电视剧免费观看高清 | 智乐星中考| 王渝萱的电影| 七年级下册语文第八课生字拼音 | 三大| 妹妹扮演的角色| nina hartley| av电影在线| 连城诀1-40集全集免费 | 无人区电影免费观看| 少爷和我短剧| 官网移动端充值| 浙江卫视今日播出节目表| 敬天法祖| 财富天下| 成吉思汗电影| 《宝莲灯》| 秀人网xiuren大尺度|

?。?!站長長期在線接?。?!

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103