我在嘗試更新mysql中的行時遇到了一些問題。mysqli->查詢在更新時返回true,但不影響行
我試着打印查詢,並在我的sql客戶端運行它,並按預期更新行。
這條線:
$這 - > mysqli->查詢($查詢);
按預期方式返回bool(true),根據php文檔(http://php.net/manual/en/mysqli.query.php)正確無誤。
失敗時返回FALSE。對於成功的SELECT,SHOW,DESCRIBE或EXPLAIN查詢,mysqli_query()將返回一個mysqli_result對象。對於其他成功的查詢,mysqli_query()將返回TRUE。
public function query($query, $parameters = array()) {
if ((is_array($parameters) && count($parameters) > 0) || (is_string($parameters) && !empty($parameters))) {
$this->lastPrepared = true;
if ($this->prepare($query) === false)
return false;
$this->bind((is_array($parameters) ? $parameters : array($parameters)));
if ($this->execute() === false)
return false;
} else {
$this->lastPrepared = false;
if (!$this->stmt = $this->mysqli->query($query)) {
debug('Query failed: (' . $this->mysqli->errno . ') ' . $this->mysqli->error);
return false;
}
}
return $this->stmt;
}
我有,四處搜尋,發現了類似我的問題的問題,但答案不幫助我找到了解決辦法。
編輯:好的,所以我現在可以看到$ this-> mysqli-> affected_rows;返回-1,這意味着有錯誤。但是,mysqli-> errno和mysqli->錯誤是空的。
我試圖運行的查詢是:
UPDATE payments_scheduled設置活動= 0 WHERE ID = 1個或ID = 2
列:
ID - 類型:int - 長度:10 - 額外:無符號,pk
active --type:tinyint - length:1 - extra:unsigned
我看不到查詢..可能是您的查詢工作正確,但不匹配行。 – scaisEdge
但如果我鍵入var_dump($查詢);在查詢功能並複製該查詢並將其粘貼到我的SQL客戶端,它工作得很好。所以問題的來源必須在上面的函數中? –
顯示查詢..更好.. – scaisEdge