Php mysql pdo查询的问题

Php mysql pdo查询的问题,php,mysql,pdo,Php,Mysql,Pdo,我的问题有问题吗 function needExport($table, $key, $id, $stamp) { try { $dbW = dbConCC(); $stmt = $dbW->prepare("SELECT * FROM :table LIMIT 10"); $params = array(':table' => "tmlaender"); $stmt->execute($params);

我的问题有问题吗

function needExport($table, $key, $id, $stamp) {
    try {
        $dbW = dbConCC();
        $stmt = $dbW->prepare("SELECT * FROM :table LIMIT 10");
        $params = array(':table' => "tmlaender");
        $stmt->execute($params);
        while ($row = $stmt->fetch()) {
            echo $row;
        }
    }
    catch(PDOException $e) {
        echo json_encode($e->getMessage());
    }
}
我得到以下语法错误:

"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''tmlaender' LIMIT 1' at line 1"
在此“简单”查询中找不到任何错误。

请尝试以下操作:

然后,当从表中回显字段时,您只需:

$var1=$var->needExport()

echo$var1->idColumn

注意:

绑定参数仅在使用
其中
时使用,例如:

public function getId($userid)
{
    $dbW = dbConCC();
    $stmt = $dbW->prepare("SELECT * FROM `users` WHERE `userid` = :uid");
    $stmt->bindParam(':uid', $userid);
    $stmt->execute();
}

为什么
:表
?因为它是一个占位符?表和列名不能用PDO中的参数替换。我最讨厌的是-投票时没有说明为什么有人决定投票。看起来表没有被替换:找不到基表或视图:1146表“ccweb.table”不存在您需要更改
table
添加到您的表名OK,但tbale name作为变量“$table”出现。但是我读到不可能准备表名和列您的表名叫什么?特兰德?
public function getId($userid)
{
    $dbW = dbConCC();
    $stmt = $dbW->prepare("SELECT * FROM `users` WHERE `userid` = :uid");
    $stmt->bindParam(':uid', $userid);
    $stmt->execute();
}