0

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 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks alot I just need to sort out my dbpassword because i get access denied for user @localhost althou I have set it usepassword to No in the xampp control panel for Mysql
aah awesome working! after fixing the password issue
Excellent! @charlie_cat

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.