I can't execute my sql in pdo,but it's work without pdo.
try{
$Attr = 'abc';
$stmt = $dbh->prepare("ALTER TABLE num ADD COLUMN ? VARCHAR(30)");
$stmt->bindValue(1,$Attr);
$stmt->execute();
print_r("<pre>");
print_r( $stmt->errorInfo());
}
catch(exception $e){
print($e->getMessage);
}
the error info is :
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 ''abc' VARCHAR(30)' at line 1
But it's right when i execute my sql statement in my mysql.
ALTER TABLE num ADD COLUMN abc VARCHAR(30); -- right
then i execute this sql:
ALTER TABLE num ADD COLUMN 'abc' VARCHAR(30); -- wrong
the error info is :
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 ''abc' VARCHAR(30)' at line 1
the same as the first info.
so,why and how to solve ?