您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php通过query查询两个字段的信息就会无法找到网页

2025/8/13 17:46:20发布17次查看
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不是主键?
其它字段呢?只要两个任意字段都有问题?
你用id查询的,还要显示id.你这个id不是主键?
其它字段呢?只要两个任意字段都有问题?
没有设置主键,只有select × from test 也是查不出来;
任意单个字段都行,任任意多个字段都不行
试试重新设计下你的表结构。。。你的建表语句拉出来看看
你直接跑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);
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);

上面的代码你写的代码测试没有问题啊
最后也不知道为什么,重装了apache,php,mysql,最后奇葩的好了
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product