如果您想要查询,那么$wpdb->last_query
(请注意,您也不需要SAVEQUERIES
, 仅当您需要每个查询的日志时($wpdb->queries
)
last_error
是哦,错误!
Update: 可能的解释last_error
为空-这是wpdb::query()
:
// If we\'re writing to the database, make sure the query will write safely.
if ( $this->check_current_query && ! $this->check_ascii( $query ) ) {
$stripped_query = $this->strip_invalid_text_from_query( $query );
// strip_invalid_text_from_query() can perform queries, so we need
// to flush again, just to make sure everything is clear.
$this->flush();
if ( $stripped_query !== $query ) {
$this->insert_id = 0;
return false;
}
}
// Redacted code
// Keep track of the last query for debug..
$this->last_query = $query;
$this->_do_query( $query );
// Redacted code
// If there is an error then take note of it..
if ( $this->use_mysqli ) {
$this->last_error = mysqli_error( $this->dbh );
} else {
$this->last_error = mysql_error( $this->dbh );
}
换句话说,WordPress似乎会预先检查查询,如果它认为查询将失败,则会中止查询-在这种情况下,您将获得
return false
但不会设置错误(因为它从未发送到MySQL服务器)。