由于某些原因,无论参数是什么以及SQL行内部的内容如何,以下代码总是返回true。它也引发一个错误“通知:未定义抵消:0在C:\ WAMP \ WWW \线路7社交网络\ INC \ login.inc”,但我看不出有什么不妥:使用fetchAll()从PDO对象中选择
<?php
function checkAccount($username, $password){
include("INC/dbconnect.inc");/*"INC/dbconnect.inc" is <?php $pdo = new PDO("mysql:host=localhost;dbname=socialnetwork","user","123"); ?>*/
$select = $pdo->prepare("SELECT id,password FROM users WHERE user_username = :username");
$select->execute(array(':username'=>$username));
$q_rows = $select->fetchAll();
if($q_rows[0][0]/*the ID of the user, it should always be greater than 1, if not then the username does not exist*/ > 0 && $q_rows[0][0] != null){
if($q_rows[0][1]/*the password of the user*/ == $password)
return true;
else
return false;
}
else
return false;
$pdo=null;
} ?>
能
人请告诉我什么是错的?我在代码里面评论了我遇到的问题,并且我尝试了正常的$select->fetch()
而不是$select->fetchAll()
无济于事。在发布之前,我已经阅读了PDO(http://php.net/manual/en/pdostatement.fetchall.php)。这里是我的文件http://pastebin.com/YCkrRivs的其余部分,谢谢。
确保你真正了解的回报 “假” 之间'的区别;'和'返回false;'。 – goat