I\'m new to pdo just tried the following and getting fatal error.
$pdo = new pdo(\'mysql:localhost;widget_corp;charset=utf-8\', \'root\', \'\');
$query = $pd
PDO::query
return false
if your query is wrong.
SELECT * FROM 'users'
should be
SELECT * FROM `users`
Use this code instead:
$pdo = new PDO('mysql:host=localhost;dbname=widget_corp;charset=UTF-8', 'root', '');
$query = $pdo->query("SELECT * FROM `users`");
$result_array = $query->fetchAll(PDO::FETCH_ASSOC);
If this doesn't work, are you sure that PDO
is installed properly?
Change:
mysql:localhost;widet_corp
to
mysql:host=localhost;dbname=widget_corp
Also in your posted code:
$query = $pdo->query("SELECT * FROM 'users'");
you have the table name inside single quotes. In Mysql you should use a backtick instead for tables and columns.
$query = $pdo->query("SELECT * FROM `users`");
$pdo->query()
will return false if the query fails. You're not initiating the pdo correctly, and you probably want to check if the query didn't return an error, so:
$pdo = new pdo('mysql:host=localhost;dbname=widget_corp;charset=utf-8', 'root', '');
$query = $pdo->query("SELECT * FROM `users`");
if($query !== false)
{
$result_array = $query->fetchAll(PDO::FETCH_ASSOC);
}