SQLSTATE [42S02]错误,提示找不到基表或视图1146

时间:2018-09-26 09:19:33

标签: php mysql pdo html-table

<?php
      $assignmentsTable = $ssubjectnamewithoutspace.'_assignments';

        try {
            $stmt = $db->query('SELECT contentID, contentTitle,contentAuthor, contentLink FROM .$assignmentsTable ORDER BY contentID ASC');
            while($row = $stmt->fetch()){

                    echo '<tr><td><a href="'.$row['contentLink'].'">'.$row['contentTitle'].'</a></td></tr>';            


            }

        } catch(PDOException $e) {
            echo $e->getMessage();
        }
    ?>

我收到此错误

  

SQLSTATE [42S02]:找不到基表或视图1146表   'epiz_5453564654654_newdata。$ assignmentsTable'不存在

但是表存在于数据库中,当我将$assignmentsTable替换为表名时,它就起作用了...

1 个答案:

答案 0 :(得分:1)

$ assignmentsTable在您的查询中不评估。

尝试:

$stmt = $db->query('SELECT contentID, contentTitle,contentAuthor, contentLink FROM `'.$assignmentsTable.'` ORDER BY contentID ASC');