Home > Backend Development > PHP Problem > php pdo attribute setting problem

php pdo attribute setting problem

coldplay.xixi
Release: 2023-03-03 06:58:02
Original
2381 people have browsed it

php pdo attribute setting method: use [PDO::setAttribute] to set attributes, the syntax structure is [bool PDO::setAttribute (int $attribute, mixed $value)].

php pdo attribute setting problem

php pdo attribute setting method:

Set the method used by PDO to process data

  • PDO::setAttribute:Set attribute

  • PDO::getAttribute:Get attribute

Syntax:

bool PDO::setAttribute ( int $attribute , mixed $value )
Copy after login

Set database handle properties. Some of the common properties available are listed below; some drivers may use additional specific properties.

Common attributes

PDO::ATTR_AUTOCOMMIT: Set whether the SQL statement of the client currently connected to the Mysql server is automatically executed. The default is automatic submission

//自动提交属性
var_dump($pdo->getAttribute(PDO::ATTR_AUTOCOMMIT));  //1
$pdo->setAttribute(PDO::ATTR_AUTOCOMMIT,0);
var_dump($pdo->getAttribute(PDO::ATTR_AUTOCOMMIT)); //0
Copy after login

PDO::ATTR_CASE: When pdo obtains data from the result set, how to process the name of the corresponding field

  • PDO::CASE_LOWER : Display all fields in lowercase letters

  • PDO::CASE_UPPER: Display all fields in uppercase letters

  • PDO::CASE_NATURAL: How it was originally How about

$pdo->setAttribute(PDO::ATTR_CASE,PDO::CASE_NATURAL);
//或 $pdo->setAttribute(PDO::ATTR_CASE,1);
var_dump(PDO::CASE_UPPER);   //1 转换为大写
var_dump(PDO::CASE_LOWER);   //2 转换为小写
var_dump(PDO::CASE_NATURAL);  //0 是怎样就是怎样
$sql = "select * from user ";
$stmt = $pdo->query($sql);
var_dump($stmt->fetch(PDO::FETCH_ASSOC));
Copy after login

PDO::ATTR_ERRMODE: Error mode, which mode is used to handle when an error occurs in pdo

  • PDO::ERRMODE_SILENT: Silent mode, the default is to ignore an error

  • PDO::ERRMODE_WARNING: Warning mode, if an error occurs, a warning will be reported

  • PDO::ERRMODE_EXCEPTION: Exception mode, if an error occurs, an exception will be used to handle it (PDOException)

var_dump($pdo->getAttribute(PDO::ATTR_ERRMODE));
var_dump(PDO::ERRMODE_SILENT);    //0 静默模式,默认的出错了不管
var_dump(PDO::ERRMODE_WARNING);    //1 警告模式,如果出错了就会报出警告
var_dump(PDO::ERRMODE_EXCEPTION);  //2 异常模式,如果出错会采用异常来处理(PDOException)
PDO::ATTR_PERSISTENT:当前对Mysql服务器的连接是否是长连接
Copy after login
  • TRUE: It is a long connection ( The use of long connections must be coordinated with: Apache (connection: keepAlive), Mysqld)

  • FALSE: Default, non-long connection

Related learning recommendations: PHP programming from entry to proficiency

The above is the detailed content of php pdo attribute setting problem. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template