<?php require_once '../classes/PdoConnect.php';?>
<?php
$login=$_POST["login"];
$password=$_POST["password"];
$sql = $pdo->prepare("SELECT id,login FROM user WHERE login=:login AND password=:password");
$sql->execute(array('login' =>$login,'password'=> $password));
$array=$sql->fetch(PDO::FETCH_ASSOC);
if($array["id"]>0){
$_SESSION['login']=$array["login"];
header('Location:admin.php');
}
else{
header('Location:Login.php');
}
?>
Выдает такую ошибку Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\OpenServer\domains\Happy\admin\login.php:6 Stack trace: #0 {main} thrown in C:\OpenServer\domains\Happy\admin\login.php on line 6
PdoConnect
<?php
class PdoConnect {
private const HOST = 'localhost';
private const DB = 'temp';
private const USER = 'root';
private const PASS = '';
private const CHARSET = 'utf8';
protected static $_instance;
protected $DSN;
protected $OPD;
public $PDO;
private function __construct() {
$this->DSN = "mysql:host=" . self::HOST . ";dbname=" . self::DB . ";charset=" . self::CHARSET;
$this->OPD = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
);
$this->PDO = new PDO($this->DSN, self::USER, self::PASS, $this->OPD);
}
public static function getInstance() {
if (self::$_instance === null)
self::$_instance = new self;
return self::$_instance;
}
private function __clone() {}
private function __wakeup() {}
}
?>