2014-12-04 47 views
-3

我有這個功能。Php - 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. " "); 

不知道我在做什麼錯在這裏。好心請

+0

流氓'='在'$ condition_var =「' – Wrikken 2014-12-04 19:39:37

+0

我真的很希望所有這些輸入參數都經過精心限制的 – tadman 2014-12-04 20:44:11

+0

是 – hellosheikh 2014-12-04 20:55:49

回答

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); 
+0

你好先生我想在這兩端使用相同的變量,像這樣$ condition_var =:$ condition_var – hellosheikh 2014-12-04 19:48:01

+0

所以,你的列名和值是一樣的? – 2014-12-04 19:56:43

+0

沒有列在我使用字符串變量和列值我發送一些值$ condition_val – hellosheikh 2014-12-04 20:02:39

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