-2

I have this code in index.php

try
{
    $db = new PDO('mysql:host=localhost;dbname=bonacadb', 'zokam', '********');
}
catch (Exception $exc)
{
    die('Database error, likely file not found or a permissions problem.');
}

I got:

Database error, likely file not found or a permissions problem.

I created database using phpMyAdmin. Any help ?

Digital Chris
  • 6,177
  • 1
  • 20
  • 29
qadenza
  • 9,025
  • 18
  • 73
  • 126

2 Answers2

2

How about trying like this?

try {
$db = new PDO('mysql:host=localhost;dbname=bonacadb', 'zokam', 'zokam1405');
} catch (PDOException $e) {
echo "Connection error: ".$e->getMessage(); exit;
}
Snow
  • 51
  • 4
1

Try using,

Also put the db name before the ip.

try{
    $dsn = 'mysql:dbname=database123;host=127.0.0.1';
    $user = 'yourusername';
    $pass = 'yourpassword';

    $dbc = new PDO($dsn, $user, $pass);
    $dbc->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
    catch (PDOException $e) {
        print "Error!: " . $e->getMessage() . "<br/>";
        die();
}

thanks JR

Jaxchief
  • 146
  • 3
  • 10