$pdo->errorCode()
$pdo->errorInfo()
<?php
header("content-type:text/html;charset=utf-8");
try {
$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
$sql = 'delete from user1 where id=2';
$res = $pdo->exec($sql);
if ($res == false) {
//$pdo->errorCode();SQLSTATE的值
echo $pdo->errorCode() . "<br/>";//42S02
//$pdo->errorInfo() 返回的错误信息的数组 数组中包含三个单元
//SQLSTATE,CODE,INFO
var_dump($pdo->errorInfo());
/**
* array
*0 => string '42S02' (length=5)
*1 => int 1146
*2 => string 'Table 'test.user1' doesn't exist' (length=32)
*/
}
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
网友评论