Home > Backend Development > PHP Tutorial > PDO查询不成功!该如何处理

PDO查询不成功!该如何处理

WBOY
Release: 2016-06-13 12:06:31
Original
1346 people have browsed it

PDO查询不成功!
代码如下:

<html><br /><meta type="text/html" charset=utf8><br /><form action="form.php" method="POST"><br /><p>名字: <input type="text" name="name" /></p><br /><p>密码: <input type="password" name="password" /></p><br /><input type="submit" /><br /></form><br /><?php<br /> error_reporting(0);<br /> $dsn = "mysql:host=localhost;dbname=liuyan";<br /> $db = new PDO($dsn, 'root', 'root');<br /> $name = $_POST['name'];<br /> $password = md5($_POST['password']);<br /> //$date = date("Y-m-d H:i:s");<br /> $sql = "select * from admin where user_name=? and password=?";<br /> $stm = $db->prepare($sql);<br /> $stm->execute(array($name,$password));<br /> $rs=$stm->fetch();<br /> var_dump($rs);<br /> if(empty($rs)){<br />    echo "<script>alert('查询失败');</script>";<br />} else{<br />    echo "<script>alert('查询成功');</script>";<br />}<br /> ?><br /></html>
Copy after login


admin表


现在问题是:fetch取出来用empty判断返回false,为啥会这样?
------解决思路----------------------
说明没有出现错误
因此可以认为你的表中没有符合条件的记录

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