Error: Call to a Member Function prepare() on null in

Asked

Viewed 17 times

1

error trying to send data.

public function __construct()
    {
        try{
            $this->conn = new PDO("mysql:dbname=lic_database;host=localhost;","root","root");

        }catch(Exception $e){
            echo $e->getMessage();
        }
    }


public function setTable(){
        $conexao = $this->conn;
        $res = $this->conn->prepare("INSERT INTO user ( username, email, password, create_time) 
        VALUES (:u, :em, :pas, :dt )");
    
        $nNome = $this->getNome();
        $nSenha = $this->getSenha();
        $nEmail = $this->getEmail();
        $objDateTime = new DateTime('NOW');


        $res->bindparam(":u",$nNome);
        $res->bindparam(":em",$nEmail);
        $res->bindparam(":pas",$nSenha);
        $res->bindParam(":td", $objDateTime);
        $res->execute();
    }
  • Probably there was some error when connecting in the bank, its class does not prevent the execution of the query there is an error, because in try/catch you just display the error message.

  • I’ll try to connect in the old mysql xampp of it, I was trying to connect by Workbench

  • Solved, I went to php.ini, removed the ";" from Extension=mysqli Extension=pdo_mysql

1 answer

0

Solved, I went to php.ini, removed the ";" of Extension=mysqli Extension=pdo_mysql

when mysql is installed on the machine via Workbench, except xampp,wampp.....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.