我正在尝试从数据库中获取结果,它没有返回任何错误,也没有返回任何结果。关于我做错了什么的任何想法?
try {
$db_connection = new PDO("mysql:host = $hostname; dbname = $database", $username, $password);
//$db_connection->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
$query = $db_connection->prepare("SELECT `id`, `code` FROM `mycodedatabase` WHERE 1");
$query->execute();
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
echo $row['id'];
echo $row['code'];
}
$db_connection = null;
}
catch(PDOException $e) {
echo $e->getMessage();
}