Php - PDO - 解析错误:语法错误,意外'。'

时间:2014-12-04 19:37:32

标签: php mysql pdo

我有这个功能。

public function selection($table, $condition_var,$condition_val)
    {
        if ($condition_var != '') {

           $stm = $this->dbh->prepare("SELECT * FROM " . $table . " WHERE " . $condition_var=.":".$condition_var. " ");
           $stm->bindParam(":".$condition_var, $condition_val);
          return $stm->execute();
        }

    }

我来到这一行

$stm = $this->dbh->prepare("SELECT * FROM " . $table . " WHERE " . $condition_var=.":".$condition_var. " ");

不知道我在这里做错了什么。请检查

2 个答案:

答案 0 :(得分:2)

请参阅:http://php.net/manual/en/pdostatement.bindparam.php

$stm = $this->dbh->prepare("SELECT * FROM " . $table . " WHERE " . $condition_var."=:condition_val");
$stm->bindParam(":condition_val", $condition_val);

答案 1 :(得分:-1)

$stm = $this->dbh->prepare("SELECT * FROM " . $table . " WHERE " . $condition_var . " = :param");
$stm->bindParam(":param", $condition_val);