Home >Backend Development >PHP Tutorial >In-depth analysis of PDO::setAttribute in PHP
##PHP Using
PDO to connect to the database is a basic operation. After using
PDO to connect to the database, what you get is# For ##Statement
type objects, we can use the setAttribute()
method to set the attributes of the database handle. This article will take you to take a look.
1. First, let’s take a look at the syntax of setAttribute(): PDO::setAttribute ( int $attribute , mixed $value )
2. About the attributes of $attribute
<?php
$servername = "localhost";
$username = "root";
$password = "root123456";
$dbname = "my_database";
$pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
echo "连接成功"."<br>";
$pdo->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
echo $pdo -> getAttribute(PDO::ATTR_CASE);
$pdo->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
echo $pdo -> getAttribute(PDO::ATTR_CASE);
$pdo->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
echo $pdo -> getAttribute(PDO::ATTR_CASE);
?>
输出: 1
2
0
Recommended:
2021 PHP interview questions summary (collection)》《php video tutorial》
The above is the detailed content of In-depth analysis of PDO::setAttribute in PHP. For more information, please follow other related articles on the PHP Chinese website!