$pdo->getAttribute()
<?php
try {
$dsn = "mysql::host=localhost;dbname=test";
$username = "root";
$password = "";
$pdo = new PDO($dsn, $username, $password);
echo "自动提交" . $pdo->getAttribute(PDO::ATTR_AUTOCOMMIT);//1
echo "<br/>";
echo 'PDO默认的错误处理模式:' . $pdo->getAttribute(PDO::ATTR_ERRMODE);
echo "<br/>";
$pdo->setAttribute(PDO::ATTR_AUTOCOMMIT, 0);
echo "自动提交" . $pdo->getAttribute(PDO::ATTR_AUTOCOMMIT);//1
} catch (PDOException $e) {
echo $e->getMessage();
}
<?php
try {
$dsn = "mysql::host=localhost;dbname=test";
$username = "root";
$password = "";
$pdo = new PDO($dsn, $username, $password);
$attrArr = array(
'AUTOCOMMIT', 'ERRMODE', 'CASE', 'PERSISTENT', 'TIMEOUT', 'ORACLE_NULLS',
'SERVER_INFO', 'SERVER_VERSION', 'CLIENT_VERSION', 'CONNECTION_STATUS'
);
foreach ($attrArr as $attr) {
echo "PDO::ATTR_$attr:";
echo @$pdo->getAttribute(constant("PDO::ATTR_$attr")), '<br/>';
}
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
$options
<?php
try {
$dsn = "mysql::host=localhost;dbname=test";
$username = "root";
$password = "";
$options = array(PDO::ATTR_AUTOCOMMIT => 0, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
$pdo = new PDO($dsn, $username, $password, $options);
echo $pdo->getAttribute(PDO::ATTR_AUTOCOMMIT);//0
echo "<br/>";
echo $pdo->getAttribute(PDO::ATTR_ERRMODE);//2
} catch (PDOException $e) {
echo $e->getMessage();
}
?>