[英]How to refer to database connection in codeigniter?
How can I call manually a PHP database function on CodeIgniter's database handler object? 如何在CodeIgniter的数据库处理程序对象上手动调用PHP数据库函数? How to retrieve the connection (
$dbc
), or call a function like mysql_real_escape_string($dbc, $variable)
? 如何检索连接(
$dbc
),或调用mysql_real_escape_string($dbc, $variable)
类的函数?
You can call any mysql native function and access mysql connection id. 您可以调用任何mysql本机函数并访问mysql连接ID。
$this->db->conn_id
will get you the current connection link object if you are in a CI context. 如果您在CI上下文中,
$this->db->conn_id
将获取当前连接链接对象。 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. 它将返回一个mysqli或mysql链接对象,您可以将其传递给
mysql_real_escape_string
或更新的mysqli等函数,这些函数实际上需要链接对象。 Source 资源
It is a better idea to use codeIgiter's functions: $this->db->escape()
, $this->db->escape_str()
, $this->db->escape_like_str()
最好使用codeIgiter的函数:
$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 ). 函数
mysql_real_escape_string()
现在已弃用(请参阅: 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 ) 而是使用
mysqli_real_escape_string
或mysqli::real_escape_string
(参见语法: http mysqli::real_escape_string
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.