执行mysql PDO SELECT但没有错误,也没有输出。为什么?

时间:2016-08-26 11:50:02

标签: php mysql pdo

我正在执行SELECT但是尽管db表中存在有效数据,但没有输出任何内容。请帮助:

我在任何地方都检查过错误并且没有错误,但我也没有输出。代码:

<?php

/*** mysql hostname ***/
$hostname = 'removed';
$dbname = 'removed';
/*** mysql username ***/
$username = 'removed';
/*** mysql password ***/
$password = 'removed';
function testdb_connect ($hostname, $username, $password){
$dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
return $dbh;
}

try {
$dbh = testdb_connect ($hostname, $username, $password);
echo 'Connected to database';
} catch(PDOException $e) {
echo $e->getMessage();
}
$dbh = testdb_connect ($hostname, $username, $password);

$id=3;
echo 'dfsdfs '.$id.' <p>';
var_dump($dbh);
$sql="SELECT * FROM removeddbname.weblog_article WHERE 'id' = :id";
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':id', $id);
$stmt->execute();
if (!$stmt) {
  echo "\nPDO::errorInfo():\n";
  print_r($dbh->errorInfo());
}
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {  
echo "Performing a select: <br>";
print_r($row);                                  
echo ' ddddddddddddddddddddd '. $row['title'];
echo 'd ddddddddd'. $row['desc']; 
}
// close the PDO connection
$link = null;
?>

上述代码的输出是:

连接到databasedfsdfs 3 对象(PDO)#2(0){}

有人可以帮忙吗?不知道该怎么办,因为我没有错误,没有输出...

1 个答案:

答案 0 :(得分:0)

删除id

附带的单引号

SELECT * FROM removeddbname.weblog_article WHERE id = :id