try{$conn=newPDO('mysql:host=localhost;dbname=s001','root','372890');}catch(Exception$err){echo$err->getMessage();}$sql="insertintouser(:table)values(:val)";$results=$con...
try{
$conn=new PDO('mysql:host=localhost;dbname=s001','root','372890');
}
catch(Exception $err){
echo $err->getMessage();
}
$sql="insert into user(:table) values(:val)";
$results=$conn->prepare($sql);
$results->execute(array(':table'=>'user002',':val'=>'001'));
print_r($results->errorInfo());
print_r($conn->errorInfo());
出现: 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 ''user002') values('001')' at line 1
换成
$sql="insert into user(user002) values(:val)";
$results=$conn->prepare($sql);
$results->execute(array(':val'=>'001'));
这样可以成功插入数据库,求解
$sql="insert into user("."$table".") values(:val)";这样也不行.
$sql="insert into user(user002) values(".":val".")";这样可以.
展开