dragon8002 2019-04-08 06:59
浏览 135
已采纳

CodeIgniter中正确的SQL查询给出错误

When I am running a query from CodeIgniter, I am getting this error.

    A Database Error Occurred
    Error Number: 42000/263
    [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Must specify 
    table to select from.
    SELECT *
    Filename: D:/xampp/htdocs/4hifi/system/database/DB_driver.php

Which is confusing cause exactly the same query executed directly in SQL-Server is giving correct results.

I am using CodeIgniter 3.1.9 , I already tried to inject $username variable to query in different ways, all are giving the same error.

Here is the code:

$sql = "select date, g1.product_name, g2.order_amount, g1.price, g1.id, g1.order_id, g1.action from dbo.orders g1 inner join (select product_name, SUM( order_amount) as order_amount from dbo.orders where action=1 and confirmed!=1 group by product_name) g2 on g2.product_name = g1.product_name where g1.confirmed !=1 and g1.kontrahent = ? and action = 1";

        $db2->query($sql, $username);


        $result = $db2->get()->result_array();

        return $result;
  • 写回答

2条回答 默认 最新

  • donglu8334 2019-04-08 07:22
    关注

    The $db2->query($sql, $username); line itself should return the required result.No need to do db->get() in case of raw queries.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?