user4005632
user4005632

Reputation:

pdo exception "colunt not find driver in ..."

in mainpage.php file, I use this:

<?php
$dsn = 'mysql:host=localhost;dbname=webfilter_schema';
$username = 'root';
$password = '';

$dbh = new PDO($dsn, $username, $password); //WORKS.

and its fine. But in another php file:

<?php

class HomeController {

public $pdoObject; // handle of the db connexion
private static $instance;

public function __construct()
{
    $dsn = 'mysql:host=localhost;dbname=webfilter_schema';
    $user = "root";
    $password = "";
    $this->$pdoObject = new PDO($dsn, $user, $password);// Error line..
}

public function createLocalObject(){
    $query ="INSERT INTO USERS SET NAME = ?, PASSWORD = ?,IPADDRESS=?,E_MAIL=?";
    $process = $this->pdoObject->prepare($query);
    $insertResult = $process->execute(array("asd","ferfr","23","[email protected]"));

    if($insertResult)
    {
        return true;
    }
    return false;
  }
}

?>

it throws an exception like

Cannot access empty property in C:\xampp\htdocs\WP\Controller\HomeController.php5 on line 25

what is it happen ?

Upvotes: 1

Views: 68

Answers (1)

user4005632
user4005632

Reputation:

just added language as parameter..

public function __construct() { 
$dsn = 'mysql:host=localhost;dbname=webfilter_schema'; 
$username = 'root'; 
$password = ''; 
$options = array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', );
$this->pdoObjectp = new PDO($dsn, $username, $password, $options); 
} 

and it works.

Upvotes: 2

Related Questions