【问题标题】:How to refer to database connection in codeigniter?如何在codeigniter中引用数据库连接?
【发布时间】:2012-04-23 00:47:08
【问题描述】:

如何在 CodeIgniter 的数据库处理程序对象上手动调用 PHP 数据库函数?如何找回连接($dbc),或者调用mysql_real_escape_string($dbc, $variable)之类的函数?

【问题讨论】:

    标签: php mysql codeigniter


    【解决方案1】:

    你可以调用任意mysql原生函数,访问mysql连接id。

    CodeIgniter User Guide

    【讨论】:

    【解决方案2】:

    $this->db->conn_id 如果您在 CI 上下文中,将为您获取当前的连接链接对象。它将返回一个 mysqli 或 mysql 链接对象,您可以将其传递到 mysql_real_escape_string 或更新后的 mysqli 等函数中,这实际上需要链接对象。 Source

    【讨论】:

      【解决方案3】:

      最好使用 codeIgiter 的函数: $this->db->escape() ,$this->db->escape_str() ,$this->db->escape_like_str()

      函数 mysql_real_escape_string() 现在已被弃用(参见:http://php.net/mysql_real_escape_string)。

      改为使用mysqli_real_escape_stringmysqli::real_escape_string(语法参见:http://www.php.net/manual/en/mysqli.real-escape-string.php

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-16
        • 1970-01-01
        • 1970-01-01
        • 2011-05-20
        • 1970-01-01
        相关资源
        最近更新 更多