Je souhaite imprimer une instruction SQL ayant échoué dans CodeIgniter. Lors de mon premier essai, j'ai utilisé un bloc try/catch ci-dessous qui imprime db-> last_query(). Cependant, comme vous pouvez le voir dans le journal, l'instruction SQL n'est pas imprimée. Qu'est-ce que je fais mal?Impression d'une instruction SQL ayant échoué dans Codeigniter
public function get($limit = NULL, $offset = NULL, $sort = NULL, $search = NULL)
{
try {
if ($limit !== NULL) $limit = (int) $limit;
if ($offset !== NULL) $offset = (int) $offset;
if (is_array($sort)) {
foreach ($sort as $field => $order) {
$this->db->order_by($field, $order);
}
}
if (is_array($search)) {
foreach ($search as $field => $match) {
$this->db->where($field, $match);
}
}
$this->db->select($this->select_fields);
$query = $this->db->get($this->table_name, $limit, $offset);
// Set the results
$this->last_query = $this->db->last_query();
$this->num_rows = $query->num_rows();
$this->result_array = $query->result_array();
$this->db_result = $query;
$this->error_number = $this->db->_error_number();
$this->error_message = $this->db->_error_message();
} catch(Exception $e) {
log_message('error',$e->getMessage());
log_message('error',$this->db->last_query());
$this->error_number = 500;
}
}
L'erreur que je reçois est:
DEBUG - 2013-03-02 15:16:50 --> DB Transaction Failure
ERROR - 2013-03-02 15:16:50 --> Query error: Unknown column 'template' in 'where clause'
Je pense que cela pourrait vous aider à: http: // stackoverflow.com/a/15860744/1199612 –