【问题标题】:Php - PDO - Parse error: syntax error, unexpected '.' [closed]Php - PDO - 解析错误:语法错误,意外的“。” [关闭]
【发布时间】:2014-12-04 19:37:32
【问题描述】:

我有这个功能。

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. " ");

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

【问题讨论】:

  • 流氓= in $condition_var=."
  • 我真的希望所有这些输入参数都受到严格限制。
  • 这里有什么问题吗?

标签: php mysql pdo


【解决方案1】:

请参考: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);

【讨论】:

  • 您好先生,我想在两端使用相同的变量,例如 $condition_var =:$condition_var
  • 那么,你的列名和值是一样的吗?
  • 没有在列我使用字符串变量,对于列值我发送一些值 $condition_val
  • 绑定参数实际上分配了变量。然后您需要在查询中使用该分配的变量。
【解决方案2】:
$stm = $this->dbh->prepare("SELECT * FROM " . $table . " WHERE " . $condition_var . " = :param");
$stm->bindParam(":param", $condition_val);

【讨论】:

    猜你喜欢
    • 2013-10-02
    • 1970-01-01
    • 2018-01-08
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-02
    • 2011-10-26
    相关资源
    最近更新 更多