PDO::setAttribute

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

PDO::setAttribute Set an attribute

Description

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

Sets an attribute on the database handle. Some available generic attributes are listed below; some drivers may make use of additional driver specific attributes. Note that driver specific attributes must not be used with other drivers.

PDO::ATTR_CASE

Force column names to a specific case. Can take one of the following values:

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 mode of PDO. Can take one of the following values:

PDO::ERRMODE_SILENT
Only sets error codes.
PDO::ERRMODE_WARNING
Raises E_WARNING diagnostics.
PDO::ERRMODE_EXCEPTION
Throws PDOExceptions.
PDO::ATTR_ORACLE_NULLS

Note: This attribute is available with all drivers, not just Oracle.

Determines if and how null and empty strings should be converted. Can take one of the following values:

PDO::NULL_NATURAL
No conversion takes place.
PDO::NULL_EMPTY_STRING
Empty strings get converted to null.
PDO::NULL_TO_STRING
null gets converted to an empty string.
PDO::ATTR_STRINGIFY_FETCHES

Whether to convert numeric values to strings when fetching. Takes a value of type bool: true to enable and false to disable.

PDO::ATTR_STATEMENT_CLASS

Set user-supplied statement class derived from PDOStatement. Requires array(string classname, array(mixed constructor_args)).

Caution

Cannot be used with persistent PDO instances.

PDO::ATTR_TIMEOUT

Specifies the timeout duration in seconds. Takes a value of type int.

Note:

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 a writable lock, but other drivers may interpret this as a connection or a read timeout interval.

PDO::ATTR_AUTOCOMMIT

Note: Only available for the OCI, Firebird, and MySQL drivers.

Whether to autocommit every single statement. Takes a value of type bool: true to enable and false to disable. By default, true.

PDO::ATTR_EMULATE_PREPARES

Note: Only available for the OCI, Firebird, and MySQL drivers.

Whether enable or disable emulation of prepared statements. Some drivers do not support prepared statements natively or have limited support for them. If set to true PDO will always emulate prepared statements, otherwise PDO will attempt to use native prepared statements. In case the driver cannot successfully prepare the current query, PDO will always fall back to emulating the prepared statement.

PDO::MYSQL_ATTR_USE_BUFFERED_QUERY

Note: Only available for the MySQL driver.

Whether to use buffered queries. Takes a value of type bool: true to enable and false to disable. By default, false.

PDO::ATTR_DEFAULT_FETCH_MODE

Set the default fetch mode. A description of the modes and how to use them is available in the PDOStatement::fetch() documentation.

Parameters

attribute

The attribute to modify.

value

The value to set the attribute, might require a specific type depending on the attribute.

Return Values

Returns true on success or false on failure.

See Also

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial