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

WBOY
Release: 2016-06-13 12:24:32
Original
1058 people have browsed it

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

本帖最后由 lsjhxl 于 2015-08-31 23:22:10 编辑
<?php<br />header("Content-Type:text/html;charset=utf-8");<br />try{<br />$pdo=new pdo('mysql:host=localhost;dbname=lsj','root','lsjhxl123') or die("链接失败");;<br />$pdo->setAttribute(PDO::ATTR_ERRMODE,2);<br />$aa=$pdo->query("set names utf8");<br />//$pdo->exec("insert into test values(2,'bb','cccccc')") or die("失败");<br /><br />$res=$pdo->query("select name from test where id = 11");//修改为查询 name,id两个字段,就错误<br />}catch(PDOException $err){<br />	echo $err->getMessage();}<br /><br />$result=$res->fetchall(PDO::FETCH_ASSOC);<br />print_r($result);;<br />?>
Copy after login


执行这个可以正确得到结果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中间是不是误用中文标点了
------解决思路----------------------
你这个逗号不对呦
------解决思路----------------------
<br />header("Content-Type:text/html;charset=utf-8");<br />try{<br />$pdo=new pdo('mysql:host=localhost;dbname=test','root','root') or die("链接失败");;<br />$pdo->setAttribute(PDO::ATTR_ERRMODE,2);<br />$aa=$pdo->query("set names gbk");<br />//$pdo->exec("insert into test values(2,'bb','cccccc')") or die("失败");<br /> <br />$res=$pdo->query("select id, goodprice from price where id = 15");//修改为查询 name,id两个字段,就错误<br />}catch(PDOException $err){<br />    echo $err->getMessage();}<br /> <br />$result=$res->fetchall(PDO::FETCH_ASSOC);<br />print_r($result);
Copy after login


上面的代码你写的代码测试没有问题啊

------解决思路----------------------
1.先确定你数据库中是否有id字段。
2.使用这句试,估计你的写法混杂了中文符号。
<br />$res=$pdo->query("select id,name from test where id=11");<br />
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!