nikeblue 发表于 2017-3-20 17:05:21

换PDO要 注意什么

CI版本是3.x的以前就是直接用php_mysql的 现在想换成pdo_mysql需要注意什么 是否只要修改config中database.php的配置即可 ?

Hex 发表于 2017-3-20 17:39:27

是的。

nikeblue 发表于 2017-3-21 10:01:09

Hex 发表于 2017-3-20 17:39
是的。

换了PDO 下面这种语句查出来就是空的。。
$this->db->select('*')
                                 ->from('article')
                                 ->where('atid',21)
                                       ->group_start()
                                       ->like('keyword','|HELLO|','both')
                                       ->or_like('keyword','HELLO|','after')
                                       ->or_like('keyword','|HELLO','before')
                                       ->group_end()
                                       ->get();

Hex 发表于 2017-3-21 10:37:19

nikeblue 发表于 2017-3-21 10:01
换了PDO 下面这种语句查出来就是空的。。
$this->db->select('*')
                                 ->from('article')


用 last_query() 看看具体生成的 SQL 语句是什么?

nikeblue 发表于 2017-3-21 11:02:58

Hex 发表于 2017-3-21 10:37
用 last_query() 看看具体生成的 SQL 语句是什么?

结果:
object(CI_DB_pdo_result)#17 (8) { ["conn_id"]=> object(PDO)#14 (0) { } ["result_id"]=> object(PDOStatement)#16 (1) { ["queryString"]=> string(177) "SELECT * FROM `sls_article` WHERE `atid` = 21 AND ( `keyword` LIKE '%|关羽|%' ESCAPE '!' OR `keyword` LIKE '关羽|%' ESCAPE '!' OR `keyword` LIKE '%|关羽' ESCAPE '!' )" } ["result_array"]=> array(0) { } ["result_object"]=> array(0) { } ["custom_result_object"]=> array(0) { } ["current_row"]=> int(0) ["num_rows"]=> NULL ["row_data"]=> NULL }




查询语句
$query=$this->db->select('*')
                                 ->from('article')
                                 ->where('atid',21)
                                       ->group_start()
                                       ->like('keyword','|关羽|','both')
                                       ->or_like('keyword','关羽|','after')
                                       ->or_like('keyword','|关羽','before')
                                       ->group_end()
                                       ->get();
var_dump($query);





是不是我用的->get 函数不对? 有没有ci pdo的函数手册

nikeblue 发表于 2017-3-21 11:04:39

nikeblue 发表于 2017-3-21 11:02
结果:
object(CI_DB_pdo_result)#17 (8) { ["conn_id"]=> object(PDO)#14 (0) { } ["result_id"]=> obje ...

我发现echo $query->num_rows() ; 这样是能查到总行数的

Hex 发表于 2017-3-21 12:20:25

nikeblue 发表于 2017-3-21 11:02
结果:
object(CI_DB_pdo_result)#17 (8) { ["conn_id"]=> object(PDO)#14 (0) { } ["result_id"]=> obje ...
没有 CI PDO 手册,CI 只有一种数据库接口,他会帮你屏蔽底层不同驱动的接口,参考手册 http://codeigniter.org.cn/user_guide/database/query_builder.html 和 http://codeigniter.org.cn/user_guide/database/results.html

我觉得是你的 SQL 写的有问题,建议放到 phpmyadim 里测试后再使用。

nikeblue 发表于 2017-3-21 15:09:28

nikeblue 发表于 2017-3-21 11:04
我发现echo $query->num_rows() ; 这样是能查到总行数的

是我犯了低级错误get后没用result:loveliness:
页: [1]
查看完整版本: 换PDO要 注意什么