我在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.');
}
我得到了:
Database error, likely file not found or a permissions problem.
我使用phpMyAdmin创建了数据库。有什么帮助吗?
答案 0 :(得分:2)
这样试试怎么样?
try {
$db = new PDO('mysql:host=localhost;dbname=bonacadb', 'zokam', 'zokam1405');
} catch (PDOException $e) {
echo "Connection error: ".$e->getMessage(); exit;
}
答案 1 :(得分:1)
尝试使用,
同时将数据库名称放在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();
}
感谢 JR