使用 oci8 数据库驱动程序在 Codeigniter 中组合 oracle sql AND OR 查询
combining oracle sql AND OR queries in Codeigniter using oci8 database drivers
我正在使用 codeigniter OCI8 数据库驱动程序,任何人都可以帮助我如何使用 $this->db->group_start()
。
如果这在 oci8 中不起作用,那么任何替代选项
我正在使用基于 ajax 的数据表。
在页面加载数据表时有效,但在搜索数据表的情况下 return 此错误
Fatal error: Call to undefined method CI_DB_oci8_driver::group_start()
这是我的代码
function _get_datatables_query(){
$this->db->from($this->table);
$i = 0;
foreach($this->column_search as $item){
if(strtoupper($_POST['search']['value'])) // if datatable send POST for search
{
if($i===0) // first loop
{
$this->db->group_start();
$this->db->like($item, strtoupper($_POST['search']['value']));
}
else
{
$this->school_db->or_like($item, strtoupper($_POST['search']['value']));
}
$this->db->group_end();
// if(count($this->column_search) - 1 == $i) //last loop
// $this->db->group_end(); //close bracket
}
$i++;
}
if(isset($_POST['order'])) // here order processing
{
$this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else if(isset($this->order))
{
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
我不知道会抛出哪个错误 - 但你的函数不会那样工作 - 请尝试以下方法
function _get_datatables_query()
{
$this->db->from($this->table);
$this->db->group_start();
foreach($this->column_search as $item)
{
if(strtoupper($_POST['search']['value'])) // if datatable send POST for search
{
$this->db->or_like($item, strtoupper($_POST['search']['value']));
}
}
$this->db->group_end();
if(isset($_POST['order'])) // here order processing
{
$this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else if(isset($this->order))
{
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
我已经通过一些自定义编码解决了这个问题。
我只是把 Like 放在 Where 子句中
$this->db->where("(" .$item ." LIKE '%".strtoupper($_POST['search']['value']."%'" ));
这是适合我的解决方案
private function _get_datatables_query()
{
$this->db->from($this->table);
$i = 0;
foreach ($this->column_search as $item)
{
if(strtoupper($_POST['search']['value'])) // if datatable send POST for search
{
if($i===0) // first loop
{
if(count($this->column_search) > 1)
$this->db->where("(" .$item . " LIKE '%".strtoupper($_POST['search']['value']."%'"));
else
$this->db->where("(" .$item . " LIKE '%".strtoupper($_POST['search']['value']."%')"));
}
else
{
if(count($this->column_search) - 1 == $i)
$this->db->or_where($item . " LIKE '%".strtoupper($_POST['search']['value']."%')"));
else
$this->db->or_where($item . " LIKE '%".strtoupper($_POST['search']['value']."%'"));
}
}
$i++;
}
if(isset($_POST['order'])) // here order processing
{
$this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else if(isset($this->order))
{
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
我正在使用 codeigniter OCI8 数据库驱动程序,任何人都可以帮助我如何使用 $this->db->group_start()
。
如果这在 oci8 中不起作用,那么任何替代选项 我正在使用基于 ajax 的数据表。
在页面加载数据表时有效,但在搜索数据表的情况下 return 此错误
Fatal error: Call to undefined method CI_DB_oci8_driver::group_start()
这是我的代码
function _get_datatables_query(){
$this->db->from($this->table);
$i = 0;
foreach($this->column_search as $item){
if(strtoupper($_POST['search']['value'])) // if datatable send POST for search
{
if($i===0) // first loop
{
$this->db->group_start();
$this->db->like($item, strtoupper($_POST['search']['value']));
}
else
{
$this->school_db->or_like($item, strtoupper($_POST['search']['value']));
}
$this->db->group_end();
// if(count($this->column_search) - 1 == $i) //last loop
// $this->db->group_end(); //close bracket
}
$i++;
}
if(isset($_POST['order'])) // here order processing
{
$this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else if(isset($this->order))
{
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
我不知道会抛出哪个错误 - 但你的函数不会那样工作 - 请尝试以下方法
function _get_datatables_query()
{
$this->db->from($this->table);
$this->db->group_start();
foreach($this->column_search as $item)
{
if(strtoupper($_POST['search']['value'])) // if datatable send POST for search
{
$this->db->or_like($item, strtoupper($_POST['search']['value']));
}
}
$this->db->group_end();
if(isset($_POST['order'])) // here order processing
{
$this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else if(isset($this->order))
{
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
我已经通过一些自定义编码解决了这个问题。 我只是把 Like 放在 Where 子句中
$this->db->where("(" .$item ." LIKE '%".strtoupper($_POST['search']['value']."%'" ));
这是适合我的解决方案
private function _get_datatables_query()
{
$this->db->from($this->table);
$i = 0;
foreach ($this->column_search as $item)
{
if(strtoupper($_POST['search']['value'])) // if datatable send POST for search
{
if($i===0) // first loop
{
if(count($this->column_search) > 1)
$this->db->where("(" .$item . " LIKE '%".strtoupper($_POST['search']['value']."%'"));
else
$this->db->where("(" .$item . " LIKE '%".strtoupper($_POST['search']['value']."%')"));
}
else
{
if(count($this->column_search) - 1 == $i)
$this->db->or_where($item . " LIKE '%".strtoupper($_POST['search']['value']."%')"));
else
$this->db->or_where($item . " LIKE '%".strtoupper($_POST['search']['value']."%'"));
}
}
$i++;
}
if(isset($_POST['order'])) // here order processing
{
$this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else if(isset($this->order))
{
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}