在被告知访问数据库的旧方法不正确之后。我现在已经开始使用 PDO 对象了。我正在设置一个简单的查询,但我没有得到任何结果。任何帮助或建议将不胜感激。它甚至没有将查询打印回给我。打开错误消息会有所帮助吗?
<?php
//print_r(PDO::getAvailableDrivers());
$config['db'] = array( //This is the config array with the database details
'host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'website'
);
$db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname' . $config['db']['dbname'], $config['db']['username'], $config['db']['password']); //Instanciate an PDO Object
$query = $db->query("SELECT 'articles'.'title' FROM 'articles'");//running a query from the database
print_r($query); //printing a query
//while ($row = $query->fetch(PDO::FETCH_ASSOC)){
// echo $row['title'], '<br>';
//}