我一直在努力让PDO在过去一个月左右工作。我不能这样做。无论我尝试哪个教程,我都会遇到错误。有人可以帮帮我吗?
我现在正在尝试这个准备声明:
<?php
include("inc/connPDO.php"); // hostname, username and password and dbName are in here
try {
$dbh = new PDO("mysql:host=$hostname;dbname=$dbName", $username, $password);
/*** echo a message saying we have connected ***/
echo 'Connected to database';
/*** The SQL SELECT statement ***/
$weaponType=1;
$sql = "SELECT * FROM rofWeapons WHERE weaponType=:weaponType";
$stmt = $dbh->prepare($sql);
$stmt->bindValue(':weaponType', $weaponType, PDO::PARAM_INT);
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
while($row = $stmt->fetch()) {
print $row['weaponName'] .' - '. $row['weaponType'] . '<br />';
}
/*** close the database connection ***/
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
输出结果为:
连接数据库
否则这会给我一个空白输出。没有。没有错误。什么都没有。
请帮忙。我做错了什么?