Configuration CodeIgniter is the PDO type, but how can not query the data, but to investigate how many records.
Code
Follow the code carefully and find the following sentence:
#文件 /system/database/drivers/pdo/pdo_driver.php function _execute($sql) { $sql = $this->_prep_query($sql); $result_id = $this->conn_id->prepare($sql); if (is_object($result_id) && $result_id->execute()) { if (is_numeric(stripos($sql, 'SELECT'))) { $this->affect_rows = count($result_id->fetchAll()); } else { $this->affect_rows = $result_id->rowCount(); } } else { $this->affect_rows = 0; return FALSE; } return $result_id; }
Problem
$this->affect_rows = count($result_id->fetchAll());
The CI here uses $result _id->fetchall () to count the number of matches, but the fetchall () cannot get the data once it is executed once. This results in the inability to obtain data later.
Test
db->query($sql)->result_array(); }}
//这样写就会有结果记录,但是默认的 $this->db->query($sql) .. 却又成摆设了!class User_model extends CI_Model{ public function getList(){ $sql = "select * from ci_user"; $stmt = $this->db->conn_id->prepare($sql); $stmt->execute(); return $stmt->fetchAll(); }}
Should not be supported, but the official website download with PDO package.
Do you want to confirm that CodeIgniter really supports PDO? Hope to give an example!
Reply content:
Configuration CodeIgniter is the PDO type, but how can not query the data, but to investigate how many records.
Code
Follow the code carefully and find the following sentence:
#文件 /system/database/drivers/pdo/pdo_driver.php function _execute($sql) { $sql = $this->_prep_query($sql); $result_id = $this->conn_id->prepare($sql); if (is_object($result_id) && $result_id->execute()) { if (is_numeric(stripos($sql, 'SELECT'))) { $this->affect_rows = count($result_id->fetchAll()); } else { $this->affect_rows = $result_id->rowCount(); } } else { $this->affect_rows = 0; return FALSE; } return $result_id; }
Problem
$this->affect_rows = count($result_id->fetchAll());
The CI here uses $result _id->fetchall () to count the number of matches, but the fetchall () cannot get the data once it is executed once. This results in the inability to obtain data later.
Test
db->query($sql)->result_array(); }}
//这样写就会有结果记录,但是默认的 $this->db->query($sql) .. 却又成摆设了!class User_model extends CI_Model{ public function getList(){ $sql = "select * from ci_user"; $stmt = $this->db->conn_id->prepare($sql); $stmt->execute(); return $stmt->fetchAll(); }}
Should not be supported, but the official website download with PDO package.
Do you want to confirm that CodeIgniter really supports PDO? Hope to give an example!
Can expand the next driver