PDO::setAttribute

Microsoft Drivers for PHP for SQL Server

Collapse image Expand Image Copy image CopyHover image

Sets a predefined PDO attribute or a custom driver attribute.

Syntax

bool PDO::setAttribute ( $attribute, $value );

Parameters

$attribute: The attribute to set. See the Remarks section for a list of supported attributes.

$value: The value (type mixed).

Return Value

Returns true on success, otherwise false.

Remarks

Attribute

Processed by

Supported values

Description

PDO::ATTR_CASE

PDO

PDO::CASE_LOWER

PDO::CASE_NATURAL

PDO::CASE_UPPER

Specifies the case of column names.

PDO::CASE_LOWER causes lower case column names.

PDO::CASE_NATURAL (the default) displays column names as returned by the database.

PDO::CASE_UPPER causes column names to upper case.

This attribute can be set using PDO::setAttribute.

PDO::ATTR_DEFAULT_FETCH_MODE

PDO

See the PDO documentation.

See the PDO documentation.

PDO::ATTR_ERRMODE

PDO

PDO::ERRMODE_SILENT

PDO::ERRMODE_WARNING

PDO::ERRMODE_EXCEPTION

Specifies how the driver will report failures.

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

PDO::ERRMODE_WARNING raises E_WARNING.

PDO::ERRMODE_EXCEPTION causes an exception to be thrown.

This attribute can be set using PDO::setAttribute.

PDO::ATTR_ORACLE_NULLS

PDO

See the PDO documentation.

Specifies how nulls should be returned.

PDO::NULL_NATURAL does no conversion.

PDO::NULL_EMPTY_STRING converts an empty string to null.

PDO::NULL_TO_STRING converts null to an empty string.

PDO::ATTR_STATEMENT_CLASS

PDO

See the PDO documentation.

Sets the user-supplied statement class derived from PDOStatement.

Requires array(string classname, array(mixed constructor_args)).

See the PDO documentation for more information.

PDO::ATTR_STRINGIFY_FETCHES

PDO

true or false

Converts numeric values to strings when retrieving data.

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.

The default is 10240 KB (10 MB).

For more information about queries that create a client-side cursor, see Cursor Types (PDO_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.

Sets the character set encoding used by the driver to communicate with the server.

PDO::SQLSRV_ENCODING_BINARY is not supported.

The default is PDO::SQLSRV_ENCODING_UTF8.

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

Microsoft Drivers for PHP for SQL Server

integer

Sets the size of the query buffer.

The default is 0, which indicates unlimited buffer size.

Negative numbers are not allowed.

For more information about queries that create a client-side cursor, see Cursor Types (PDO_SQLSRV Driver).

PDO processes some of the predefined attributes and requires the driver to process others. All custom attributes and connection options are processed by the driver. An unsupported attribute, connection option, or unsupported value will be reported according to the setting of PDO::ATTR_ERRMODE.

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

Example

This sample shows how to set the PDO::ATTR_ERRMODE attribute.

  Copy imageCopy Code
<?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" ) ));
   }
?>

See Also

Reference

Other Resources

PDO