Пытаюсь добавить запись в бд, но получаю ошибку:
Fatal error: Uncaught Error: Call to a member function prepare() on null in E:\OSPanel\domains\test.ru\classes\_new.db.php:30
Stack trace:
#0 E:\OSPanel\domains\test.ru\api\ajax.php(19): db->prep('INSERT INTO db_...')
#1 {main}
thrown in <b>E:\OSPanel\domains\test.ru\classes\_new.db.php</b> on line 30
$db->prep("INSERT INTO db_users_a (user, email, pass, referer, referer_id, date_reg, ip)
VALUES (?, ?, ?, ?, ?, ?, ?)");
$arr = array('$login', '$email', '$pass', 'admin', '1', '$time', INET_ATON('$ip'));
$db->prep($arr);
Класс $db:
<?PHP
class db{
private $config;
private $arr;
public function __construct(Config $config)
{
$this->config = $config;
$this->connect();
}
private function connect()
{
$host = $this->config->host;
$dbname = $this->config->base;
$charset = $this->config->charset;
$user = $this->config->user;
$pass = $this->config->pass;
$dsn = "mysql:host=$host;dbname=$dbname;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_LAZY,
PDO::ATTR_EMULATE_PREPARES => false,
];
$pdo = new PDO($dsn, $user, $pass, $opt);
return $this;
}
public function prep($sql, $arr=array())
{
$stmt = $this->pdo->prepare($sql);
return $stmt->execute($arr);
}
}
?>
Не могу понять что ему не хватает)