首页 > 解决方案 > Laravel 查询生成器不返回数据

问题描述

我有一个查询生成器,由于某种原因,即使表中有数据,它也会返回 null,我已经通过获取查询生成器生成的 sql 并在 HeidiSQL 中运行它来确认这一点,并且确实有数据。

以下是代码:

$billSource = DB::table('trea.audit_bill_master')
    ->select('source')
    ->where('fin_year', $fin_year)
    ->where('bill_no', $val)
    ->where('trea_code', $trea_code)
    ->first();

这是生成的SQL:

array:1 [
  0 => array:3 [
    "query" => "select "source" from "trea"."audit_bill_master" where "fin_year" = ? and "bill_no" = ? and "trea_code" = ? limit 1"
    "bindings" => array:3 [
      0 => "2021-2022"
      1 => "146"
      2 => "20"
    ]
    "time" => 1.14
  ]
]

我使用 postgres 9.3 作为我的数据库和 laravel 5.8 版

标签: phplaraveleloquentpostgresql-9.3

解决方案


推荐阅读