I'm in a new project, and I need to use prepare()
of the PDO, I do not know why, but only with it that is giving this error, every time it has some function, or some line with prepare()
, PHP returns an error.
I have already searched the entire OS, I found answers, but I tried them all and no question was the same as mine / or it was similar, but the answer did not resolve.
Page code conexao.php
:
$pdo = new PDO("mysql:host=localhost;dbname=central", "root", "");
Page code index.php
:
require_once('conexao.php');
$sql = $pdo->prepare("INSERT INTO logs VALUES (:id, :type, :info)");
$sql->execute(array(":id" => NULL, ":type" => $type, ":info" => $info));
Informed error:
Notice: Undefined variable: pdo in C:\xampp\htdocs\index.php on line 2
Fatal error: Call to a member function prepare() on null in C:\xampp\htdocs\index.php on line 2