Редагувати

Поділитися через


PDO::getAttribute

Download PHP driver

Retrieves the value of a predefined PDO or driver attribute.

Syntax

  
mixed PDO::getAttribute ( $attribute )  

Parameters

$attribute: One of the supported attributes. See the Remarks section for the list of supported attributes.

Return Value

On success, returns the value of a connection option, predefined PDO attribute, or custom driver attribute. On failure, returns null.

Remarks

The following table contains the list of supported attributes.

Attribute Processed by Supported Values Description
PDO::ATTR_CASE PDO PDO::CASE_LOWER

PDO::CASE_NATURAL

PDO::CASE_UPPER
Specifies whether the column names should be in a specific case. PDO::CASE_LOWER forces lower case column names, PDO::CASE_NATURAL leaves the column name as returned by the database, and PDO::CASE_UPPER forces column names to upper case.

The default is PDO::CASE_NATURAL.

This attribute can also be set using PDO::setAttribute.
PDO::ATTR_CLIENT_VERSION Microsoft Drivers for PHP for SQL Server Array of strings Describes the versions of the driver and related libraries. Returns an array with the following elements: ODBC version (MajorVer.MinorVer), SQL Server Native Client DLL name and version, Microsoft Drivers for PHP for SQL Server version (MajorVer.MinorVer.BuildNumber.Revision)
PDO::ATTR_DEFAULT_STR_PARAM PDO PDO::PARAM_STR_CHAR

PDO::PARAM_STR_NATL
If not set to PDO::PARAM_STR_CHAR, PDO::PARAM_STR_NATL is returned.
PDO::ATTR_DRIVER_NAME PDO String Always returns "sqlsrv".
PDO::ATTR_DRIVER_VERSION Microsoft Drivers for PHP for SQL Server String Indicates the Microsoft Drivers for PHP for SQL Server version (MajorVer.MinorVer.BuildNumber.Revision)
PDO::ATTR_ERRMODE PDO PDO::ERRMODE_SILENT

PDO::ERRMODE_WARNING

PDO::ERRMODE_EXCEPTION
Specifies how failures should be handled by the driver.

PDO::ERRMODE_SILENT (the default) sets the error codes and information.

PDO::ERRMODE_WARNING raises an E_WARNING.

PDO::ERRMODE_EXCEPTION raises an exception.

This attribute can also be set using PDO::setAttribute.
PDO::ATTR_ORACLE_NULLS PDO See the PDO documentation. See the PDO documentation.
PDO::ATTR_SERVER_INFO Microsoft Drivers for PHP for SQL Server Array of 3 elements Returns the current database, SQL Server version, and SQL Server instance.
PDO::ATTR_SERVER_VERSION Microsoft Drivers for PHP for SQL Server String Indicates the SQL Server version (Major.Minor.BuildNumber)
PDO::ATTR_STRINGIFY_FETCHES PDO See PDO documentation See the PDO documentation.
PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE Microsoft Drivers for PHP for SQL Server 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 (SQLSRV Driver).
PDO::SQLSRV_ATTR_DIRECT_QUERY Microsoft Drivers for PHP for SQL Server true

false
Specifies direct or prepared query execution. For more information, see Direct Statement Execution and Prepared Statement Execution in the PDO_SQLSRV Driver.
PDO::SQLSRV_ATTR_ENCODING Microsoft Drivers for PHP for SQL Server PDO::SQLSRV_ENCODING_UTF8

PDO::SQLSRV_ENCODING_SYSTEM
Specifies the character set encoding used by the driver to communicate with the server.

The default is PDO::SQLSRV_ENCODING_UTF8.
PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE Microsoft Drivers for PHP for SQL Server 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, even when SQLSRV_ATTR_FETCHES_NUMERIC_TYPE is on, the return value is a string.

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_QUERY_TIMEOUT Microsoft Drivers for PHP for SQL Server integer Sets the query timeout in seconds.

The default is 0, which means the driver will wait indefinitely for results.

Negative numbers are not allowed.

PDO processes some of the predefined attributes while it requires the driver to handle others. All custom attributes and connection options are handled by the driver, an unsupported attribute or connection option returns null.

Support for PDO was added in version 2.0 of the Microsoft Drivers for PHP for SQL Server.

Example

This example shows the value of the PDO::ATTR_ERRMODE attribute, before and after changing its value.

<?php  
$database = "AdventureWorks";  
$conn = new PDO( "sqlsrv:server=(local) ; Database = $database", "", "");  
  
$attributes1 = array( "ERRMODE" );  
foreach ( $attributes1 as $val ) {  
     echo "PDO::ATTR_$val: ";  
     var_dump ($conn->getAttribute( constant( "PDO::ATTR_$val" ) ));  
}  
  
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );  
  
$attributes1 = array( "ERRMODE" );  
foreach ( $attributes1 as $val ) {  
     echo "PDO::ATTR_$val: ";  
     var_dump ($conn->getAttribute( constant( "PDO::ATTR_$val" ) ));  
}  
  
// An example using PDO::ATTR_CLIENT_VERSION  
print_r($conn->getAttribute( PDO::ATTR_CLIENT_VERSION ));  
?>  

See Also

PDO Class

PDO