我正在嘗試用PHP創建一個登錄/註冊碼,它將註冊數據發送到數據庫。我調用execute()方法,但出於某種原因,它不起作用。應該發生什麼是該方法發送SQL語句到數據庫我忽略了什麼?PHP PDO :: execute語句不會執行
public function query($sql, $params= array()) {
/* query takes 2 paramaters, $sql which is a prepared sql statement, and params, which holds the value of the fields to be inserted into db */
$this->_error = false; // field to determine if there is an error
$this->_query = $this->_pdo->prepare($sql); // $_query is another field holding the query value
$x=1;
if(count($params)){ //count is a function to determine if the paramater has a value
foreach($params as $param) {
$this->_query->bindValue($x, $param);
$x++;
}
}
if($this->_query->execute($sql)){
$this->_result = $this->_query->fetchAll(PDO::FETCH_OBJ);
$this->_count = $this->_query->rowCount(); // this is the block that is desired to be executed
} else {
$this->_error = true; // This is the block that is being executed
}
return $this;
}
我驗證有連接到數據庫沒有問題了,裏面查詢其他方法(i)根據需要
請編輯你的問題來澄清它。尋求調試幫助的問題(「**爲什麼不是這個代碼工作?」)必須包括所需的行爲,*特定的問題或錯誤*和*在問題本身中重現它*所需的最短代碼* *。沒有**明確問題陳述**的問題對其他讀者沒有用處。請參閱:[如何創建一個最小,完整和可驗證的示例。](http://stackoverflow.com/help/mcve) –
您可以詳細說明'它不起作用'嗎? –
爲什麼創建一個名爲query的函數時,該函數自己已經存在? –