“在使用预准备语句时,在非对象上调用成员函数prepare()”

时间:2014-03-10 22:07:41

标签: php prepared-statement

所以我为我的网站创建了一个论坛,我介绍了一个问题,这里是

  

致命错误:在第3行的/home/a8479867/public_html/pages/forum/index.php中调用非对象的成员函数prepare()

这是我的代码

<?php
//...
$query=$db->prepare('SELECT cat_id, cat_nom, 
forum_forum.forum_id, forum_name, forum_desc, forum_post, forum_topic, auth_view, forum_topic.topic_id,  forum_topic.topic_post, post_id, post_time, post_createur, membre_pseudo, 
membre_id 
FROM forum_categorie
LEFT JOIN forum_forum ON forum_categorie.cat_id = forum_forum.forum_cat_id
LEFT JOIN forum_post ON forum_post.post_id = forum_forum.forum_last_post_id
LEFT JOIN forum_topic ON forum_topic.topic_id = forum_post.topic_id
LEFT JOIN forum_membres ON forum_membres.membre_id = forum_post.post_createur
WHERE auth_view <= :lvl 
ORDER BY cat_ordre, forum_ordre DESC');
$query->bindValue(':lvl',$lvl,PDO::PARAM_INT);
$query->execute();
?>

1 个答案:

答案 0 :(得分:0)

你还没有创造出&#34; db&#34;你在第3行打电话的对象

对于mysqli来说,它是$ db = new mysqli(&#39; localhost&#39;,&#39; my_user&#39;,&#39; my_password&#39;,&#39; db&#39;);

因为看起来你正在使用它的$ db = new PDO(&#39; mysql:host = localhost; dbname = testdb; charset = utf8&#39;,&#39; username&#39;,&#39;密码&#39);