Può regredire con questo esempio?
Codice PHP:
<?php
error_reporting(-1);
$dsn = 'mysql:dbname=my_tdef;host=127.0.0.1';
$user = 'googleguy';
$password = 'googleguy';
/*
Using try/catch around the constructor is still valid even though we set the ERRMODE to WARNING since
PDO::__construct will always throw a PDOException if the connection fails.
*/
try {
$dbh = new PDO($dsn, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
exit;
}
// This will cause PDO to throw an error of level E_WARNING instead of an exception (when the table doesn't exist)
$d = false;
$sth = $dbh->query("SELECT * FROM stanze");
if(is_object($sth))
$d = $sth->execute();
if($d !== true)
$d = false;
var_dump($sth, $d);
Nota* presti attenzione alle Maiuscole o minuscole per i nomi di tabella e i campi.