PDO::getAttribute

 

DownloadDownload PHP Driver

Retrieves the value of a predefined PDO or driver attribute.

  
mixed PDO::getAttribute ( $attribute )  

Parameters

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

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

The following table contains the list of supported attributes.

AttributeProcessed bySupported ValuesDescription
PDO::ATTR_CASEPDOPDO::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_VERSIONMicrosoft Drivers for PHP for SQL ServerArray of stringsDescribes 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_FETCH_MODEPDOSee the PDO documentation.See the PDO documentation.
PDO::ATTR_DRIVER_NAMEPDOStringAlways returns "sqlsrv".
PDO::ATTR_DRIVER_VERSIONMicrosoft Drivers for PHP for SQL ServerStringIndicates the Microsoft Drivers for PHP for SQL Server version (MajorVer.MinorVer.BuildNumber.Revision)
PDO::ATTR_ERRMODEPDOPDO::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_NULLSPDOSee the PDO documentation.See the PDO documentation.
PDO::ATTR_SERVER_INFOMicrosoft Drivers for PHP for SQL ServerArray of 3 elementsReturns the current database, SQL Server version, and SQL Server instance.
PDO::ATTR_SERVER_VERSIONMicrosoft Drivers for PHP for SQL ServerStringIndicates the SQL Server version (Major.Minor.BuildNumber)
PDO::ATTR_STATEMENT_CLASSPDOSee PDO documentationSee PDO documentation. (returns PDOStatement)
PDO::ATTR_STRINGIFY_FETCHESPDOSee PDO documentationSee the PDO documentation.
PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZEMicrosoft Drivers for PHP for SQL Server1 to the PHP memory limit.Configures the size of the buffer that holds the result set for a client-side cursor.

The default is 10240 KB (10 MB).

For more information about client-side cursors, see Cursor Types (SQLSRV Driver).
PDO::SQLSRV_ATTR_DIRECT_QUERYMicrosoft Drivers for PHP for SQL Servertrue

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_ENCODINGMicrosoft Drivers for PHP for SQL ServerOne of the following:

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 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 will return null.

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

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

PDO Class
PDO

Community Additions

ADD
Show: