Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refer to database connection in 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)?

like image 940
zarkoz Avatar asked Apr 23 '12 00:04

zarkoz


2 Answers

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

See CodeIgniter User Guide

like image 78
Ula Avatar answered Nov 14 '22 21:11

Ula


$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

like image 45
erstaples Avatar answered Nov 14 '22 21:11

erstaples