Chuyển đến nội dung chính
Trình duyệt này không còn được hỗ trợ nữa.
Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật.
PDOStatement::fetchObject
- Bài viết
- 09/09/2022
- 2 phút để đọc
Trong bài viết này
Retrieves the next row as an object.
Syntax
mixed PDOStatement::fetchObject[[ $class_name[,$ctor_args ]] ]
Parameters
$class_name: An optional string specifying the name of the class to create. The default is stdClass.
$ctor_args: An optional array with arguments to a custom class constructor.
Return Value
On success, returns an object with an instance of the class. Properties map to columns. Returns false on failure.
Remarks
Support for PDO was added in version 2.0 of the Microsoft Drivers for PHP for SQL Server.
Example
See Also
PDOStatement Class
PDO
Phản hồi
Gửi và xem ý kiến phản hồi dành cho
6 năm trước
Ẩn danh ¶ — Fetches the next row and returns it as an object
Vegard lkken ¶
8 năm trước PDOStatement::fetchObject[?string $class
=
"stdClass", array $constructorArgs
= []]: object|false
[Php 5> = 5.1.0, Php 7, Php 8, Pecl PDO> = 0.2.4]
Pdostatement :: fetchobject - tìm nạp hàng tiếp theo và trả về nó dưới dạng đối tượng
Sự mô tảpublicPdostatement :: fetchObject [? chuỗi $class
= "stdClass", mảng $constructorArgs
= []]: object | false
Thông số
class
Tên của lớp được tạo.false
on failure.
constructorArgs
¶
9 năm trước
Be warned of the rather unorthodox behavior of PDOStatement::fetchObject[] which injects property-values BEFORE invoking the constructor - in other words, if your class initializes property-values to defaults in the constructor, you will be overwriting the values injected by fetchObject[] !
A var_dump[$this] in your __construct[] method will reveal that property-values have been initialized prior to calling your constructor, so be careful.
For this reason, I strongly recommend hydrating your objects manually, after retrieving the data as an array, rather than trying to have PDO apply properties directly to your objects.
0
1
2Val Bancer ¶ ¶
2 năm trước
3Sebastian Dot Rapetti tại Alice Dot it ¶ ¶
5 năm trước
4
5
6
7
8
9đang được ¶
7 năm trước
$class
0
$class
1
$class
2
$class
3Dave tại Davidhbrown dot chúng tôi ¶ ¶
7 năm trước
$class
4
$class
5
2Dave tại Davidhbrown dot chúng tôi ¶ ¶
ZLK1214 tại Gmail Dot Com ¶
$class
7
$class
8
$class
96 năm trước ¶
7 năm trước
$constructorArgs
0
$constructorArgs
1
$constructorArgs
2
$constructorArgs
3Dave tại Davidhbrown dot chúng tôi ¶ ¶
ZLK1214 tại Gmail Dot Com ¶
$constructorArgs
4
$constructorArgs
5
$constructorArgs
6
$constructorArgs
7