PHP
数据库 | Database

PDO::setAttribute

PDO::setAttribute

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)

PDO::setAttribute — Set an attribute

Description

public bool PDO::setAttribute ( int $attribute , mixed $value )

Sets an attribute on the database handle. Some of the available generic attributes are listed below; some drivers may make use of additional driver specific attributes.

  • PDO::ATTR_CASE: Force column names to a specific case.

- _PDO::CASE\_LOWER_: Force column names to lower case. - _PDO::CASE\_NATURAL_: Leave column names as returned by the database driver. - _PDO::CASE\_UPPER_: Force column names to upper case.

  • PDO::ATTR_ERRMODE: Error reporting.

- _PDO::ERRMODE\_SILENT_: Just set error codes. - _PDO::ERRMODE\_WARNING_: Raise [E\_WARNING](pdo.setattribute). - _PDO::ERRMODE\_EXCEPTION_: Throw [exceptions](class.pdoexception).

  • PDO::ATTR_ORACLE_NULLS (available with all drivers, not just Oracle): Conversion of NULL and empty strings.

- _PDO::NULL\_NATURAL_: No conversion. - _PDO::NULL\_EMPTY\_STRING_: Empty string is converted to **`NULL`**. - _PDO::NULL\_TO\_STRING_: NULL is converted to an empty string.

  • PDO::ATTR_STRINGIFY_FETCHES: Convert numeric values to strings when fetching. Requires bool.

Return Values

Returns TRUE on success or FALSE on failure.

← PDO::rollBack

PDOStatement →

© 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

https://secure.php.net/manual/en/pdo.setattribute.php