我在codeigniter中遇到以下错误
错误号:1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `appID` = 'buttn_default'' at line 2
SELECT `responseURL` WHERE `appID` = 'buttn_default'
这是我用于从数据库获取数据的模态函数
function get_response_url($appID, $merchant_id)
{
$this->db->select('responseURL');
$this->db->from('response_urls');
$this->db->where('appID',$appID);
//$this->db->or_where('merchant_id',$merchant_id);
$query = $this->db->get();
if($query->num_rows() == 1)
{
foreach($query->result() as $row)
return $row->responseURL;
}
else
{
$appID='buttn_default';
$this->db->select('responseURL');
$this->db->where('appID',$appID);
$query = $this->db->get();
if($query->num_rows() == 1)
foreach($query->result() as $row)
return $row->responseURL;
}
}
为什么不起作用,为什么我会得到这个错误.
解决方法:
您的mysql错误显示没有from子句,而您的else部分也与活动记录的from()函数一起丢失
else
{
$appID='buttn_default';
$this->db->select('responseURL');
$this->db->from('table_name_here'); <------
$this->db->where('appID',$appID);
$query = $this->db->get();
if($query->num_rows() == 1)
foreach($query->result() as $row)
return $row->responseURL;
}