Php REGEXP查询无法正确处理变量

Php REGEXP查询无法正确处理变量,php,mysql,codeigniter,Php,Mysql,Codeigniter,我有一个问题,需要将代码点火器查询从jquery插入的代码应用到数据库中,我只需要字母数字字符 我一直在使用REGEXP来清理我不想要的字符,如果我直接在查询中键入字符,查询就可以工作,但是如果我使用另一个查询中的变量,查询就不能工作 <?php $this->db->select('niv'); $this->db->from('tbl_notes'); $this->db->where('notes_id', $not

我有一个问题,需要将代码点火器查询从jquery插入的代码应用到数据库中,我只需要字母数字字符

我一直在使用REGEXP来清理我不想要的字符,如果我直接在查询中键入字符,查询就可以工作,但是如果我使用另一个查询中的变量,查询就不能工作

<?php    
    $this->db->select('niv');
    $this->db->from('tbl_notes');
    $this->db->where('notes_id', $notes_id);
    $query = $this->db->get();
    if($query->num_rows()){
        $niv = $query->result();
    }
    $this->db->select('*');
    $this->db->from('tbl_flotilla_history');
    $this->db->where('notes REGEXP ', "'.*;s:[0-9]+:\"$niv\".*'", false); 
    $this->db->limit(10);
    $query = $this->db->get();
    if($query->num_rows()){
        $history = $query->result();
    }
?>
试试这个:

<?php
    $history = NULL;
    $this->db->select('niv');
    $this->db->from('tbl_notes');
    $this->db->where('notes_id', $notes_id);
    $query = $this->db->get();
    if($query->num_rows()) $niv = $query->result();
    $this->db->select('*');
    $this->db->from('tbl_flotilla_history');
    $this->db->where('notes REGEXP ', '".*;s:[0-9]+:\"'.$niv.'\".*"', false);
    $this->db->limit(10);
    $query = $this->db->get();
    if($query->num_rows()) $history = $query->result();
try
$this->db->where('notes REGEXP',“'.*;s:[0-9]+:\”.$niv.\“*”,false)