If CodeIgniter is set to PDO type, but no data can be found, how many records can be investigated. The Code carefully tracks the code and finds the following sentence: {code ...} question {code ...} here, CI uses $ result_id-& amp; gt; fetchAll () to calculate the number of qualified items ,... if CodeIgniter is set to PDO type, but no data can be found, how many records can be investigated.
Code
After carefully tracking the code, we found the following sentence:
# File/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());
Here, CI uses $ result_id-> fetchAll () to count the number of qualified items. However, after this fetchAll () operation, data cannot be obtained again. Therefore, data cannot be obtained later.
Test
Db-> query ($ SQL)-> result_array ();}}
// As a result, the default $ this-> db-> query ($ SQL)... is displayed! 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 ();}}
It should not be supported, but the download on the official website contains the PDO package.
Do codeigniter really support PDO? I hope to give an example!
Reply content:
If CodeIgniter is set to PDO type, but no data can be found, how many records can be investigated.
Code
After carefully tracking the code, we found the following sentence:
# File/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());
Here, CI uses $ result_id-> fetchAll () to count the number of qualified items. However, after this fetchAll () operation, data cannot be obtained again. Therefore, data cannot be obtained later.
Test
Db-> query ($ SQL)-> result_array ();}}
// As a result, the default $ this-> db-> query ($ SQL)... is displayed! 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 ();}}
It should not be supported, but the download on the official website contains the PDO package.
Do codeigniter really support PDO? I hope to give an example!
Extended driver