php - pdo exception "colunt not find driver in ..." -
in mainpage.php file, use this:
<?php $dsn = 'mysql:host=localhost;dbname=webfilter_schema'; $username = 'root'; $password = ''; $dbh = new pdo($dsn, $username, $password); //works.
and fine. in php file:
<?php class homecontroller { public $pdoobject; // handle of 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 users set name = ?, password = ?,ipaddress=?,e_mail=?"; $process = $this->pdoobject->prepare($query); $insertresult = $process->execute(array("asd","ferfr","23","sadsads@hotmail.com")); if($insertresult) { return true; } return false; } } ?>
it throws exception
cannot access empty property in c:\xampp\htdocs\wp\controller\homecontroller.php5 on line 25
what happen ?
just added language 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 works.
Comments
Post a Comment