Does CodeIgniter support PDO queries? Example

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.