php - codeigniter 中的这个数据库错误是什么

标签 php mysql codeigniter

我在 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;
    }

关于php - codeigniter 中的这个数据库错误是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23205114/

相关文章:

javascript - 尝试在 node-js/express 中代理图像

php - 如何为 set socks 5 或 php stream_socket_client 的 http 代理制作上下文数组

具有零到多个参数的 SQL In 子句

php - 在 codeigniter mysql 中使用 where 条件获取空白页

php - Silverstripe 从单独的页面类型访问 has_many 数据

php - 根据 2 个组合框的选择搜索数据库 - php

MySQL 使用没有 auto_increment 的递增值填充新列

MySQL SELECT 不为空时

php - 从 url 中删除 index.php 文件 codeigniter 在 Windows 服务器中不起作用

javascript - ajax 函数不会转到 php codeigniter Controller