如何在codeigniter中引用数据库连接?
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)
?
如何在CodeIgniter的数据库处理程序对象上手动调用PHP数据库函数? 如何检索连接( $ dbc code>),或调用类似
mysql_real_escape_string($ dbc,$ variable) code>的函数? p>
div>
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)
$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