PDO and INSERT Fatal error: Uncaught Error: Call to a member function prepare() on null What to do?

I just started learning PDO, do not judge strictly ))
function __autoload($name){ include($_SERVER['DOCUMENT_ROOT']."/classes/_new.".$name.".php");}
$config = new config;
$db = new db($config);
global $pdo;
//variables + check
$pdo->prepare("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'));

The connection is a third-party file with the db class
class db{
 private $config;
 public function __construct(Config $config)
 $this->config = $config;

 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 = new PDO($dsn, $user, $pass, $opt);
 return $this;

Assume that the case of $db->$pdo->prepare(...). Tried different ($db->prepape, $db->pdo->prepare, $pdo->prepare) nothing happens. When all in one file is easy to do. But then you need some way to refer to the pdo in the class. I think you need to do the functions prepare() and execute() in class db, but in this case, to pass an array with the data for the query?
The full text of the error:
Fatal error: Uncaught Error: Call to a member function prepare() on null in E:\OSPanel\domains\test.ru\api\ajax.php:19
Stack trace:
#0 {main}
 thrown in <b>E:\OSPanel\domains\test.ru\api\ajax.php on line 19</b>

Connect correctly. Immediately apologize for such a sloppy description of the problem.
June 3rd 19 at 19:22
1 answer
June 3rd 19 at 19:24
$db = new db($config);
Decide how your variable is called $db or $pdo
I say in different ways tried to do this using the $db but also did not work. $pdo was the final version. - Lurline.Pacocha65 commented on June 3rd 19 at 19:27
apparently, crooked wrote a wrapper class. Try this wrapper inherit from class PDO
Here examples of such wrappers: https://phpdelusions.net/pdo/pdo_wrapper - Tod commented on June 3rd 19 at 19:30

Find more questions by tags PHP PDO