我选择了一个表但是在错误部分它告诉我我已经选择了另一个表。我不知道为什么会发生这种情况。我在某些视图中查询,但没有问题。这个问题不是在任何地方。但在一些视图和控制器。
这是我的MY_Model
protected function from()
{
return $this->db->from($this->_table_name);
}
protected function where()
{
if(is_array($this->_where))
{
foreach($this->_where as $where)
{
return $this->db->where($where['field_name'],$where['primary_key']);
}
}
else
{
return $this->db->where($this->_field_name,$this->_primary_key);
}
}
protected function or_where()
{
if(is_array($this->_where))
{
foreach($this->_where as $where)
{
return $this->db->or_where($where['field_name'],$where['primary_key']);
}
}
else
{
$this->db->or_where($this->_or_field_name,$this->_or_primary_key);
}
}
protected function join()
{
if(is_array($this->_join))
{
foreach($this->_join as $join)
{
return $this->db->join($join['table'],$join['query']);
}
}
else
{
return 'Invalid Query';
}
}
protected function order()
{
//print_r($this->_order);exit();
if(is_array($this->_order))
{
return $this->db->order_by($this->_order['by'],$this->_order['order']);
}
else
{
return "Invalid Query";
}
}
protected function limit()
{
if(is_array($this->_limit))
{
foreach($this->_limit as $limit)
{
return $this->db->limit($limit['from'],$limit['to']);
}
}
else
{
return $this->db->limit($this->_limit);
}
}
public function get()
{
$this->db->select('*');
if($this->_table_name)
{
$this->from();
}
if($this->_where || ($this->_field_name && $this->_primary_key))
{
$this->where();
}
if($this->_or_where || ($this->_or_field_name && $this->_or_primary_key))
{
$this->or_where();
}
if($this->_join)
{
$this->join();
}
if($this->_order)
{
$this->order();
}
if($this->_limit)
{
$this->limit();
}
return $this->db->get();
}
这是我的查询
$this->cm->_table_name = "products";
$this->cm->_field_name = "products.productID";
$this->cm->_primary_key = $productID;
$this->cm->_join = array
(
array
(
'table' => 'product_details',
'query' => 'products.productID=product_details.productID',
'type' => 'left',
),
);
$data['product'] = $this->cm->get();
这是错误
Error Number: 1064
您的SQL语法有错误;查看与您的MariaDB服务器版本对应的手册,以获得正确的语法,以便在' * FROM'产品',' parentcategory'附近使用。在哪里'产品'。' productID' =' 30''在第1行
SELECT *, * FROM `products`, `parentcategory` WHERE `products`.`productID` = '30'
Filename: C:/xampp/htdocs/mv/system/database/DB_driver.php
Line Number: 691
我不知道为什么会这样,请帮助我。
答案 0 :(得分:0)
使用以下内容更改您的查询:
SELECT products.*, parentcategory.* FROM `products`, `parentcategory` WHERE `products`.`productID` = '30'
或
SELECT * FROM `products`, `parentcategory` WHERE `products`.`productID` = '30'
您可以添加其他参数,例如:
$this->cm->_field_to_select = "products.*,parentcategory.*";
并将其添加到get方法
中if ($this->_field_to_select) {
$this->db->select($this->_field_to_select);
}
else {
$this->db->select('*');
}