我在pdo遇到了一个大问题,似乎没有人可以帮助我 - 所以我决定问你们: - )
try {
$links = $database->prepare("SELECT * FROM aTable WHERE visible=:visible AND access<=:access AND category=:category ORDER BY orderNum ASC");
$links->bindValue(':visible',$first,PDO::PARAM_INT);
$links->bindValue(':access',$second,PDO::PARAM_INT);
$links->bindValue(':category',$third,PDO::PARAM_STR);
$links->execute();
print_r($asdf);
print_r($database->errorInfo());
print_r($links->errorInfo());
while($row = $links->fetch(PDO::FETCH_ASSOC)){
print_r($row);
}
} catch (PDOException $e) {
echo $e->getMessage();
}
Database-Connection工作正常,errorInfo()都返回:
Array
(
[0] => 00000
[1] =>
[2] =>
)
现在,这段代码不知何故得到任何$ row。但是如果我用以下几行替换prepare语句:
$sql = "SELECT * FROM woody_sidebar WHERE visible=$first AND access<=$second AND category=$third ORDER BY orderNum ASC";
$links = $database->prepare($sql);
(并删除bindValue语句)代码就像魅力一样!
我不知道我做错了什么,因为没有任何错误 - 你们中有人知道我能尝试什么吗?
由于
答案 0 :(得分:0)
改变这个:
$links = $database->prepare("SELECT * FROM aTable WHERE visible=:visible AND access<=:access AND category=:category ORDER BY orderNum ASC");
$links->bindValue(':visible',$first,PDO::PARAM_INT);
$links->bindValue(':access',$second,PDO::PARAM_INT);
$links->bindValue(':category',$third,PDO::PARAM_STR);
到此:
在第二个查询中,您的表名为
传递woody_sidebar
,但您有aTable
而第三个问题是INT
,可以作为PDO::PARAM_INT
$links = $database->prepare("SELECT * FROM woody_sidebar WHERE visible=:visible AND access<=:access AND category=:category ORDER BY orderNum ASC");
$links->bindValue(':visible',$first,PDO::PARAM_INT);
$links->bindValue(':access',$second,PDO::PARAM_INT);
$links->bindValue(':category',$third,PDO::PARAM_INT);
答案 1 :(得分:0)
我看到的唯一问题是你的桌名。
试试这个
try {
$sql = "SELECT * FROM woody_sidebar WHERE visible=:visible AND access<=:access AND category=:category ORDER BY orderNum ASC";
$links = $database->prepare($sql);
$links->bindValue(':visible', $first, PDO::PARAM_INT); // assuming this is an integer
$links->bindValue(':access', $second, PDO::PARAM_INT); // assuming this is an integer
$links->bindValue(':category', $third, PDO::PARAM_STR); // assuming this is an text string or date
$links->execute();
print_r($asdf);
print_r($database->errorInfo());
print_r($links->errorInfo());
while($row = $links->fetch(PDO::FETCH_ASSOC)){
print_r($row);
}
} catch (PDOException $e) {
echo $e->getMessage();
}
快乐的编码!