0
votes

i have this code:

 try {
   $pdo = new PDO("mysqli:host=$databasehost;dbname=$databasename", 
    $databaseusername, $databasepassword,
    array(
        PDO::MYSQL_ATTR_LOCAL_INFILE => true,
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
    )
 );
 } catch (PDOException $e) {
    die("database connection failed: ".$e->getMessage());
 }

my code goes straigh to the catch what have i got wrong here?

i have the pdo drivers enabled when i do a phpinfo():

PDO drivers mysql, sqlite pdo_mysql

PDO Driver for MySQL enabled Client API version mysqlnd 5.0.11-dev - 20120503 - $Id: f373ea5dd5538761406a8022a4b8a374418b240e $

and in php.ini i have: extension=php_pdo_mysql.dll without the semicolon in front

1

1 Answers

2
votes

Try it like this:

try {
    $pdo = new PDO('mysql:host=' . $databasehost . ';dbname=' . $databasename , $databaseusername, $databasepassword, array(PDO::MYSQL_ATTR_LOCAL_INFILE=>1));
}
catch (PDOException $e) {
    die('Error!: ' . $e->getMessage() . '<br/>');
}
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec("set names utf8");

Whilst MYSQL_ATTR_LOCAL_INFILE needs to be set in the initial string, ATTR_ERRMODE is set thereafter.

If your credentials are correct, this will work.