【问题标题】:protect_identifiers issue in codeigniter 3.1.0codeigniter 3.1.0 中的protect_identifiers 问题
【发布时间】:2016-12-16 21:30:02
【问题描述】:

在以前的版本 2.2.6 中,我使用以下代码:

$this->db->_protect_identifiers=false;

$dataField='tm.*,IFNULL(CONCAT_WS(" " ,pm.firstName,pm.lastName),"") as assignedToName,IFNULL(cm.caseNo,"") as CaseNo,IFNULL(cm1.fileNo,"") as fileNo,IFNULL(sm.caseStage,"") as caseStage';

$qryTable='task_mst as tm 
            LEFT JOIN case_mst as cm on tm.caseNo=cm.ID
            LEFT JOIN case_mst as cm1 on tm.fileNo=cm1.ID
            LEFT JOIN party_mst as pm on tm.assignedTo=pm.ID
            LEFT JOIN session_mst as sm on tm.sessionId=sm.ID';
$task= $this->db->select($dataField,false)->from($qryTable)->where($where,NULL,FALSE)->order_by("ID","desc")->limit(10)->get()->result_array();

现在我使用的是 3.1.0 版,但是“_protect_identifiers”会给出错误信息

Fatal error: Cannot access protected property CI_DB_mysqli_driver::$_protect_identifiers

谁能告诉我如何在 codeigniter 3.1.0 中使用“protect_identifiers()”?

【问题讨论】:

  • 也许它现在需要一个访问器方法,例如set_protect_identifiers(false); 或它的一些变体。如果是,请告诉我,我将作为答案发布。

标签: php codeigniter codeigniter-3


【解决方案1】:

这是一个示例

return 'SELECT '.$this->escape_identifiers('name')
            .' FROM '.$this->escape_identifiers('sysobjects')
            .' WHERE '.$this->escape_identifiers('type')." = 'U'";

【讨论】:

    【解决方案2】:

    只需从 $this->db->_protect_identifiers 中删除 _。 (下划线)

    $this->db->protect_identifiers=false;
    

    这是 CI 在新版本中所做的更改。

    【讨论】:

      【解决方案3】:

      尝试这样设置..

      $this->db->protect_idenifiers(FALSE)->select(...)->where(...)
      

      更多信息请参考this

      【讨论】:

      • 我使用了 "$task= $this->db->protect_identifiers(FALSE)->select($dataField,FALSE)->from($qryTable)->where($where,NULL, FALSE)->order_by("ID","desc")->limit(10)->get()->result_array();"但它给了我错误“调用非对象上的成员函数 select()”
      • 这个错误可能是在没有加载数据库时出现的。第一种方法是在你的application/config/autoload.php中包含“database”$autoload['libraries'] = array('database');或者通过$this->load->database()加载你的类构造函数;
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-27
      • 2017-03-08
      相关资源
      最近更新 更多