$dsn?=?'mysql:host=127.0.0.1;dbname=test';
$username?=?'root';
$password?=?'root';
try?{
????$pdo?=?new?PDO($dsn,?$username,?$password);
}?catch?(PDOException?$e)?{
????echo?$e->getMessage();
????exit;
}
$sql?=?'SELECT?*?FROM?:table_name';?//?命名參數(shù)
$stmt?=?$pdo->prepare($sql);
$stmt->bindParam(':table_name',?$table_name,?PDO::PARAM_STR);?//?綁定到$table_name?變量
$table_name?=?'yd_user';?//?給變量賦值
$stmt->execute();
print_r($stmt->errorInfo());
//?print_r($stmt->fetchAll());
//?--------------------------
//?輸出錯誤信息:
Array
(
????[0]?=>?42000
????[1]?=>?1064
????[2]?=>?You?have?an?error?in?your?SQL?syntax;?check?the?manual?that?corresponds?to?your?MySQL?server?version?for?the?right?syntax?to?use?near?''yd_user''?at?line?1
)
2019-01-18
其實你的SQL語句是select * from 'yd_user';
2015-10-27
修改成