Reputation: 780
I'm trying to set UTF8
encoding to PDO
construct, what I did for now is this:
public function __construct($dbType, $dbHost, $dbName, $dbUser, $dbPass, $charset)
{
try
{
parent::__construct($dbType . ':host=' . $dbHost . ';dbname=' . $dbName, $dbUser,
$dbPass. ';charset=' . $charset);
}
catch(PDOException $e)
{
$this->_error = $e->getMessage();
}
parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
parent::setAttribute(PDO::ATTR_PERSISTENT, true);
}
when the setAttribute
line is reached I get this error:
PDO::setAttribute(): SQLSTATE[00000]: No error: PDO constructor was not called
what am I doing wrong?
Upvotes: 0
Views: 115
Reputation: 948
Are you extending PDO? When i want to instanciate a PDO object i write this:
$pdoObj = new PDO(
'mysql:dbname=' . DB_NAME .
';host=' . HOST_NAME . ";",
USER,
PWD,
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
);
Upvotes: 1