dqhbuwrwq692118284 2012-04-23 00:47
浏览 39
已采纳

如何在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)?

  • 写回答

3条回答 默认 最新

  • dongtanhe4607 2012-04-23 01:12
    关注

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

    See CodeIgniter User Guide

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • douchi2022 2014-01-10 12:19
    关注

    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)

    评论
  • douwei7501 2016-09-29 17:50
    关注

    $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

    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 设置mac系统只能访问指定网站
  • ¥15 西门子博途 s7 1200控制三台步进电机
  • ¥15 基于非参数的方向距离函数求污染物影子价格(有偿)
  • ¥15 vue+element 生成table
  • ¥15 实验 4 FIFO 算法和 LRU 算法-C 程序实现
  • ¥30 电脑画面同步投屏,通过同wifi的方式投屏方法,接收投屏端不需要安装第三方软件,
  • ¥15 有偿拼接大疆精灵4RGB影像
  • ¥15 Arduino实现音频混响
  • ¥15 cuda.jit加速报错
  • ¥15 Octave 安装工具箱出错 Only Win32 target is supported!