本帖最后由 lsjhxl 于 2015-08-31 23:22:10 编辑 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);;
?>
执行这个可以正确得到结果array ( [0] => array ( [name] => aa ) )。
但是如果select name from test where id = 11变成select name,id from test where id = 11,,就直接连不上localhost,无法找到网页了
------解决思路----------------------
你用id查询的,还要显示id.你这个id不是主键?
------解决思路----------------------
其它字段呢?只要两个任意字段都有问题?
------解决思路----------------------
试试重新设计下你的表结构。。。你的建表语句拉出来看看
------解决思路----------------------
你直接跑sql语句可以吗?不用通过php代码来执行
------解决思路----------------------
name id中间是不是误用中文标点了
------解决思路----------------------
你这个逗号不对呦
------解决思路----------------------
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);
上面的代码你写的代码测试没有问题啊
------解决思路----------------------
1.先确定你数据库中是否有id字段。
2.使用这句试,估计你的写法混杂了中文符号。
$res=$pdo->query(select id,name from test where id=11);