无法使用-> where-> get;从数据库获取行;

问题描述

我在数据库中有一张名为“发票”的表格,其中列有“自动月份”和“自动年份”及其值。我不知道为什么这个函数返回空数组。我想获取具有自动月份值和自动年份值的行。请帮助我。

$autoyear = date('Y');
$automonth = date('m');

$autonumber = DB::table("invoices as invoices")
    ->where('automonth','=','$automonth')
    ->where('autoyear','$autoyear') 
    ->get();

解决方法

您以错误的方式传递了变量:

$autonumber = DB::table("invoices as invoices")
    ->where('automonth','=',$automonth)
    ->where('autoyear',$autoyear) 
    ->get();

当您传递变量名时不需要'...

,

$ automonth $ autoyear 中删除报价:

$autonumber = DB::table("invoices as invoices")
    ->where('automonth',$autoyear) 
    ->get();

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...