我有以下课程用户:
class USER
{
private $db;
//constructor que estable la conexión con la base de datos
function __construct($DB_con) {
$this->db = $DB_con;
}
//Estable el login del usuario
public function login($uname, $upass)
{
try
{
$query = $this->db->prepare("SELECT * FROM users WHERE user_name=:uname");
$query->execute(array(':uname'=>$uname, ':upass'=>$upass));
var_dump($query);
当我创建var_dump($ query);
时,我得不到任何结果我的index.php如下
require_once 'inc/config.php';
//Si el usuario esta logueado
if($user->is_loggedin())
{
$user->redirect('home.php');
}
if(isset($_POST['btn-login']))
{
var_dump('dentro');
$uname = $_POST['txt_uname'];
$upassword = $_POST['txt_password'];
if($user->login($uname,$upassword))
{
$user->redirect('home.php');
}
else
{
$error = "Nombre de usuario y/o contraseña incorrecto";
}
}
有什么问题?我在phpmyadmin中尝试查询,然后得到结果。
我做错了什么?
答案 0 :(得分:-1)
你想要获取它
public function login($uname, $upass)
{
try
{
$query = $this->db->prepare("SELECT * FROM users WHERE user_name=:uname");
$query->execute(array(':uname'=>$uname, ':upass'=>$upass));
var_dump($query->fetch(PDO::FETCH_ASSOC));