PHP--PDO property settings

Source: Internet
Author: User

Set how PDO handles data in the process

Pdo::setattribute: Setting properties

Pdo::getattribute: Get Properties

Grammar:bool pdo::setattribute ( int $attribute , mixed $value )

Sets the database handle property. Some of the common properties available are listed below, and some drivers may use additional specific properties.

Parameters

$attribute

pdo::attr_case: Enforces the column name to the specified case. His $value can be as follows:

pdo::case_lower: Enforces the column name lowercase.

pdo::case_natural: Retains the column name returned by the database driver.

pdo::case_upper: Enforces column name capitalization.

Pdo::attr_errmode: Error reporting. His $value can be as follows:

pdo::errmode_silent: Sets the error code only.

pdo::errmode_warning: Throwing e_warning Error

pdo::errmode_exception: Throws exceptions exception.

pdo::attr_oracle_nulls (available in all drivers, not limited to ORACLE): Converts null and empty strings. His $value can be as follows:

pdo::null_natural: Do not convert.

pdo::null_empty_string: Converts an empty string into NULL A.

pdo::null_to_string: Converts null to an empty string.

pdo::attr_stringify_fetches: Converts a value to a string when extracted. Requires bool.

Pdo::attr_statement_class: Sets the statement class provided by the user derived from Pdostatement. cannot be used with persistent PDO instances. An array (string class name, array (parameter of the mixed constructor) isrequired.

pdo::attr_timeout: Specifies the number of seconds to time out. Not all drivers support this option, which means there may be differences between drivers and drivers. For example, when SQLite waits for this value, it discards the acquisition of a writable lock, but other drivers may interpret this value as a connection or read time-out interval. An int type is required.

pdo::attr_autocommit (available in Oci,firebird and MySQL): whether each individual statement is automatically submitted.

pdo::attr_emulate_prepares Enables or disables impersonation of preprocessing statements. Some drivers do not support or support local preprocessing in a limited way. Use this setting to force PDO to always impersonate a preprocessing statement TRUE (if it is), or try to use a local FALSE preprocessing statement (if it is). If the driver cannot preprocess the current query successfully, it will always return to the simulated preprocessing statement. The bool type is required.

pdo::mysql_attr_use_buffered_query (available in MYSQL): Use buffered queries.

Pdo::attr_default_fetch_mode: Sets the default extraction mode. A description of the pattern can be found in the Pdostatement::fetch () document.

Common Properties

Pdo::attr_autocommit: Sets whether the SQL statement of the client currently connected to the MySQL server executes automatically, by default it is automatically committed

// Auto-Commit Properties Var_dump ($pdo->getattribute (pdo::attr_autocommit));    // 1 $pdo->setattribute (pdo::attr_autocommit,0); Var_dump ($pdo->getattribute (pdo::attr_autocommit));  // 0

Pdo::attr_case: How to handle the name of the corresponding field when PDO obtains data from the result set

Pdo::case_lower: All fields are shown in lowercase

Pdo::case_upper: All fields are shown in uppercase

Pdo::case_natural: What's the original?

    $pdo->setattribute (pdo::attr_case,pdo::case_natural); //or $pdo->setattribute (pdo::attr_case,1);    Var_dump(Pdo::case_upper);//1 Convert to uppercase    Var_dump(Pdo::case_lower);//2 Convert to lowercase    Var_dump(pdo::case_natural);//0 is how it is    $sql= "SELECT * from User"; $stmt=$pdo->query ($sql); Var_dump($stmt->fetch (PDO::FETCH_ASSOC));

Pdo::attr_errmode: Error mode, which mode is used to process PDO when an error occurs

Pdo::errmode_silent: Silent mode, default error no matter

Pdo::errmode_warning: Warning mode, warning if something goes wrong

Pdo::errmode_exception: Exception mode with exception handling if an error occurs (pdoexception)

    // Error mode    Var_dump ($pdo->getattribute (PDO::attr_errmode));     Echo pdo::errmode_silent;        // default to silent mode

Pdo::attr_persistent: Whether the current connection to the MySQL server is a long connection

TRUE: is a long connection (the use of long connections must be mated: Apache (connection:keepalive), Mysqld)

FALSE: Default, non-long connection

Under what circumstances is a long connection used?

    1. Different scripts have very short execution spacing, and each script operates the database (Mysql:mysql_pconnect ())

PHP--PDO property settings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.