Hướng dẫn dùng add attribute trong PHP

Chuyển đến nội dung chính

Nội dung chính

  • PDOStatement::setAttribute
  • Trong bài viết này
  • Return Value
  • Phản hồi
  • 1, Lớp -class.
  • 3, Phương thức.
  • 4, Khởi tạo lớp.
  • 5, Truy xuất thuộc tính của class.
  • Truy xuất trong class
  • Truy xuất ngoài class
  • 6, Truy xuất phương thức của class.
  • Truy xuất trong class.
  • Truy xuất ngoài class.
  • 7, Lời kết.

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::setAttribute

  • Bài viết
  • 09/09/2022
  • 2 phút để đọc

Trong bài viết này

Download PHP driver

Sets an attribute value, either a predefined PDO attribute or a custom driver attribute.

Syntax

bool PDOStatement::setAttribute [$attribute, $value ];  

Parameters

$attribute: An integer, one of the PDO::ATTR_* or PDO::SQLSRV_ATTR_* constants. See the Remarks section for the list of available attributes.

$value: The [mixed] value to be set for the specified $attribute.

Return Value

TRUE on success, FALSE otherwise.

Remarks

The following table contains the list of available attributes:

AttributeValuesDescription
PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE 1 to the PHP memory limit. Configures the size of the buffer that holds the result set for a client-side cursor.

The default is 10,240 KB [10 MB].

For more information about client-side cursors, see Cursor Types [PDO_SQLSRV Driver].

PDO::SQLSRV_ATTR_DATA_CLASSIFICATION true or false Specifies whether to retrieve data classification metadata when calling PDOStatement::getColumnMeta. The default is false.
PDO::SQLSRV_ATTR_DECIMAL_PLACES Integer between 0 and 4 [inclusive] Specifies the number of decimal places when formatting fetched money values.

Any negative integer or value more than 4 will be ignored.

This option works only when PDO::SQLSRV_ATTR_FORMAT_DECIMALS is true.

This option may also be set at the connection level. If so, then this option overrides the connection level option.

For more information, see Formatting Decimal Strings and Money Values [PDO_SQLSRV Driver].

PDO::SQLSRV_ATTR_ENCODING Integer

PDO::SQLSRV_ENCODING_UTF8 [Default]

PDO::SQLSRV_ENCODING_SYSTEM

PDO::SQLSRV_ENCODING_BINARY

Sets the character set encoding to be used by the driver to communicate with the server.
PDO::SQLSRV_ATTR_FETCHES_DATETIME_TYPE true or false Specifies whether to retrieve date and time types as PHP DateTime objects. If left false, the default behavior is to return them as strings.

This option may also be set at the connection level. If so, then this option overrides the connection level option.

For more information, see How to: Retrieve Date and Time Types as PHP DateTime Objects Using the PDO_SQLSRV Driver.

PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE true or false Handles numeric fetches from columns with numeric SQL types [bit, integer, smallint, tinyint, float, or real].

When connection option flag ATTR_STRINGIFY_FETCHES is on, the return value is a string even when SQLSRV_ATTR_FETCHES_NUMERIC_TYPE is on.

When the returned PDO type in bind column is PDO_PARAM_INT, the return value from an integer column is an int even if SQLSRV_ATTR_FETCHES_NUMERIC_TYPE is off.

PDO::SQLSRV_ATTR_FORMAT_DECIMALS true or false Specifies whether to add leading zeroes to decimal strings when appropriate. If set, this option enables the PDO::SQLSRV_ATTR_DECIMAL_PLACES option for formatting money types. If left false, the default behavior of returning exact precision and omitting leading zeroes for values less than 1 is used.

This option may also be set at the connection level. If so, then this option overrides the connection level option.

For more information, see Formatting Decimal Strings and Money Values [PDO_SQLSRV Driver].

PDO::SQLSRV_ATTR_QUERY_TIMEOUT Integer Sets the query timeout in seconds.

By default, the driver will wait indefinitely for results. Negative numbers are not allowed.

0 means no timeout.

Example

  

See Also

PDOStatement Class

PDO

Phản hồi

Gửi và xem ý kiến phản hồi dành cho

Mỗi một đối tượng thì sẽ có một hoặc nhiều class, và ở trong class thì sẽ có một hoặc nhiều các thuộc tính, phương thức.Và bài hôm nay chúng ta sẽ đi vào tìm hiểu lớp, thuộc tính, phương thức trong PHP.

Nội dung chính

  • 1, Lớp -class.
  • 3, Phương thức.
  • 4, Khởi tạo lớp.
  • 5, Truy xuất thuộc tính của class.
  • Truy xuất trong class
  • Truy xuất ngoài class
  • 6, Truy xuất phương thức của class.
  • Truy xuất trong class.
  • Truy xuất ngoài class.
  • 7, Lời kết.

Nội dung chính

  • 1, Lớp -class.
  • 3, Phương thức.
  • 4, Khởi tạo lớp.
  • 5, Truy xuất thuộc tính của class.
  • Truy xuất trong class
  • Truy xuất ngoài class
  • 6, Truy xuất phương thức của class.
  • Truy xuất trong class.
  • Truy xuất ngoài class.
  • 7, Lời kết.

Nội dung chính

  • 1, Lớp -class.
  • 3, Phương thức.
  • 4, Khởi tạo lớp.
  • 5, Truy xuất thuộc tính của class.
  • Truy xuất trong class
  • Truy xuất ngoài class
  • 6, Truy xuất phương thức của class.
  • Truy xuất trong class.
  • Truy xuất ngoài class.
  • 7, Lời kết.

Nội dung chính

  • 1, Lớp -class.
  • 3, Phương thức.
  • 4, Khởi tạo lớp.
  • 5, Truy xuất thuộc tính của class.
  • Truy xuất trong class
  • Truy xuất ngoài class
  • 6, Truy xuất phương thức của class.
  • Truy xuất trong class.
  • Truy xuất ngoài class.
  • 7, Lời kết.

1, Lớp -class.

-Lớp[class] dùng để mô tả một phần hoặc toàn phần của một đối tượng[nhưng không phải đối tượng]. Và để khai báo nó trong PHP thì chúng ta sử dụng cú pháp sau:

class Name
{
    //code
}

Trong đó: Name là tên của class. Nó có các rằng buộc về tên giống như đặt tên hàm trong hướng thủ tục.

VD: Mình sẽ khai báo lớp Person đại diện cho đối tượng con người chúng ta.

class Person
{
    //code
}

-Thuộc tính [properties] trong class có tác dụng như các biến và hằng trong phương pháp lập trình hướng thủ tục.Ví dụ như lớp con người sẽ có các thuộc tính như mắt, mũi, chân, tay,... Và để khai báo thuộc tính trong class chúng ta sử dụng cú pháp:

Bài Viết Liên Quan

Chủ Đề