How to refer to database connection in codeigniter?

醉酒当歌 提交于 2019-12-23 09:50:03

问题


How can I call manually a PHP database function on CodeIgniter's database handler object? How to retrieve the connection ($dbc), or call a function like mysql_real_escape_string($dbc, $variable)?


回答1:


You can call any mysql native function and access mysql connection id.

See CodeIgniter User Guide




回答2:


$this->db->conn_id will get you the current connection link object if you are in a CI context. It will return a mysqli or mysql link object that you can pass into functions like mysql_real_escape_string or the updated mysqli, which actually requires the link object. Source




回答3:


It is a better idea to use codeIgiter's functions: $this->db->escape() ,$this->db->escape_str() ,$this->db->escape_like_str()

The function mysql_real_escape_string() is deprecated by now ( see: http://php.net/mysql_real_escape_string ).

Instead use mysqli_real_escape_string or mysqli::real_escape_string (see for the syntax: http://www.php.net/manual/en/mysqli.real-escape-string.php)



来源:https://stackoverflow.com/questions/10273550/how-to-refer-to-database-connection-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!