时间:2021-07-01 10:21:17 帮助过:7人阅读
header("Content-Type:text/html;charset=utf-8");
try{
$pdo=new pdo('mysql:host=localhost;dbname=lsj','root','lsjhxl123') or die("链接失败");;
$pdo->setAttribute(PDO::ATTR_ERRMODE,2);
$aa=$pdo->query("set names utf8");
//$pdo->exec("insert into test values(2,'bb','cccccc')") or die("失败");
$res=$pdo->query("select name from test where id = 11");//修改为查询 name,id两个字段,就错误
}catch(PDOException $err){
echo $err->getMessage();}
$result=$res->fetchall(PDO::FETCH_ASSOC);
print_r($result);;
?>
header("Content-Type:text/html;charset=utf-8");
try{
$pdo=new pdo('mysql:host=localhost;dbname=test','root','root') or die("链接失败");;
$pdo->setAttribute(PDO::ATTR_ERRMODE,2);
$aa=$pdo->query("set names gbk");
//$pdo->exec("insert into test values(2,'bb','cccccc')") or die("失败");
$res=$pdo->query("select id, goodprice from price where id = 15");//修改为查询 name,id两个字段,就错误
}catch(PDOException $err){
echo $err->getMessage();}
$result=$res->fetchall(PDO::FETCH_ASSOC);
print_r($result);
$res=$pdo->query("select id,name from test where id=11");