i am newbie using this pdo to have access to the database. I am trying to get the ID from the database but I don't receive any data.
1:
$date = array(
':user' => $_POST['user'],
':pass' => $_POST['pass'],
);
$user->login($date);
2
function login ($date) {
$this->dbh->query("Select id From users Where username = ':user' and password = ':pass'");
$result = $this->dbh->execute_array($date);
$_SESSION['userid'] = $result['id'];
//header("Location: game.php");
}
3
function query($query) {
$this->stmt = $this->db->prepare($query);
}
function execute_array ($array) {
return $this->stmt->execute($array);
}
edit:
i wrote the pdo code again making some changes that resolve my problem.
function login ($date) {
$this->dbh->query("Select id From users Where username = :user and password = :pass");
$this->dbh->execute_array($date);
$result = $this->dbh->single();
$_SESSION['userid'] = $result['id'];
//header("Location: game.php");
}
function execute_array ($array) {
$this->stmt->execute($array);
}
function single() {
return $this->stmt->fetch(PDO::FETCH_ASSOC);
}
ty for helping me with this.