After being advised that the old method of access a database were not correct. I have now started using the PDO object. I am setting up a simple query but I am not getting any results back. Any help or advise would be appreciated. It is not even printing the query back to me. Would turning on error messages help?
<?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>';
//}
I would recommend you read up on PDO and error handling and reporting.
http://php.net/manual/en/pdo.error-handling.php
and
http://php.net/manual/en/pdo.errorinfo.php
They should show you how to easily get proper errors from your sql query so you can see whats going wrong.
In you’re case your query is wrong it should be
$query = $db->query("SELECT title FROM articles");No need to specify the tabl to pull from in your select param section and no need for single quotes. You should be using the back tick quote not single quote anyway `