致命错误:未捕获的异常' PDOException'

时间:2014-07-17 21:15:12

标签: php mysql fatal-error

我下载了这个网站目录,当我运行它时,我收到以下错误:

错误 致命错误:未捕获的异常' PDOException'消息' SQLSTATE [42S02]:未找到基表或视图:1146表' u471047401_test.Categories'不存在'在/home/u471047401/public_html/inc/blocks/sidebar.php:13堆栈跟踪:#0 /home/u471047401/public_html/inc/blocks/sidebar.php(13):PDOStatement-> execute(Array)#1 /home/u471047401/public_html/index.php(6):在/ home / u471047401 / public_html / inc / blocks /中输入#(' / home / u47104740 ...')#2 {main}第13行的sidebar.php

    <?
$cat = $_GET['cat'];
if(empty($cat))
{
    $cat = 0;
}
$menu_query = ("
    SELECT cat_id, cat_name, parent_cat
    FROM Categories
    WHERE (cat_id = ? OR parent_cat = ?)");

$stm = $conn->prepare($menu_query);
$stm->execute(array($cat, $cat));
("u471047401_test.Categories");
$categories = $stm->fetchAll();

?>
<div class='col-4 col-lg-4 ' style='padding-left:0;'>
    <ul class="nav nav-pills nav-stacked well;">
<?  
foreach($categories as $categories_row)
{
    $act = $categories_row['cat_id'] == $cat ? 'active' : '';
    echo"
    <li class={$act}>
        <a href='category.php?cat={$categories_row['cat_id']}'>
        {$categories_row['cat_name']}
        </a> 
      </li>";

    if($categories_row['cat_id'] == $cat && $categories_row['cat_id'] > 0)
    {
    $back_link = "<li><a href=``'category.php?cat={$categories_row['parent_cat']}' title='Go back to previous category'>Back</a></li>";
    }
}
?>  
    <?= $back_link ?>
    </ul>
</div>

导致此错误的原因是什么?

1 个答案:

答案 0 :(得分:3)

删除FROM

周围的引号
SELECT cat_id, cat_name, parent_cat  FROM  Categories
                                    ^----^-----here

如果你在它周围加上引号,那么数据库引擎会将其作为静态字符串处理,而不是作为查询的关键字