我有点困惑,因为当尝试下面的代码时,我收到了想要的结果。
include_once('config.class.php');
$db = Core::getInstance();
$whr = 'test@nannex.com';
$inv = $db->dbh->prepare("SELECT * FROM ruj_users WHERE email=:whr");
$inv->execute(array(":whr"=>$whr));
$row = $inv->fetch(PDO::FETCH_ASSOC);
echo $row['email'];
echo $row['full_name'];
但是,当我运行以下代码时,它返回 1 而不是所需的结果。
include_once('config.class.php');
$db = Core::getInstance();
$whr = 'test@nannex.com';
function fetchUser($whr){
$db = Core::getInstance();
$inv = $db->dbh->prepare("SELECT * FROM ruj_users WHERE :whr");
$inv->execute(array(':whr'=>$whr));
$res = $inv->fetch(PDO::FETCH_ASSOC);
return $res;
}
$row = fetchUser("email = '".$whr."' ");
echo $row['email'];
echo $row['full_name'];