首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

PDO::setAttribute

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

PDO::setAttribute — Set an attribute

Description

代码语言:javascript
复制
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.
代码语言:txt
复制
-  _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.
代码语言:txt
复制
- _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.
代码语言:txt
复制
- _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.
  • PDO::ATTR_STATEMENT_CLASS: Set user-supplied statement class derived from PDOStatement. Cannot be used with persistent PDO instances. Requires array(string classname, array(mixed constructor_args)).
  • PDO::ATTR_TIMEOUT: Specifies the timeout duration in seconds. Not all drivers support this option, and its meaning may differ from driver to driver. For example, sqlite will wait for up to this time value before giving up on obtaining an writable lock, but other drivers may interpret this as a connect or a read timeout interval. Requires int.
  • PDO::ATTR_AUTOCOMMIT (available in OCI, Firebird and MySQL): Whether to autocommit every single statement.
  • PDO::ATTR_EMULATE_PREPARES Enables or disables emulation of prepared statements. Some drivers do not support native prepared statements or have limited support for them. Use this setting to force PDO to either always emulate prepared statements (if TRUE and emulated prepares are supported by the driver), or to try to use native prepared statements (if FALSE). It will always fall back to emulating the prepared statement if the driver cannot successfully prepare the current query. Requires bool.
  • PDO::MYSQL_ATTR_USE_BUFFERED_QUERY (available in MySQL): Use buffered queries.
  • PDO::ATTR_DEFAULT_FETCH_MODE: Set default fetch mode. Description of modes is available in PDOStatement::fetch() documentation.

Return Values

Returns TRUE on success or FALSE on failure.

← PDO::rollBack

PDOStatement →

代码语言:txt
复制
 ? 1997–2017 The PHP Documentation Group

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com