Whenever I pass a query after a PDO connection the page returns an 500 error. I don't know whats causing the issue. I am using LAMP server. Here is the code:
$user = 'root';
$database = 'mysql';
$password = 'root';
$dbname = 'pdotest';
$host = 'localhost';
$dsn = $database . ":" . $host . ";dbname=" . $dbname;
$opt = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
);
$pdo = new PDO($dsn, $user, $password, $opt) or die('Can\'t establish connection');
// This is where it gives 500 error
$stmt = $pdo->query("SELECT * FROM pdo");