php - 无法使用 ->where()->get() 从 DB 获取行;
问题描述
我在数据库中有一个名为 invoices 的表格,以及带有值的 automonth 和 autoyear 列。我不知道为什么这个函数返回空数组。我想获取具有 automonth 值和 autoyear 值的行。请帮我。
$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();
传递变量名时不需要 '' ...
推荐阅读
- java - 编码 Eclipse 调试器与 JVM
- react-native - 在 React Native 上使用 ConnectyCube 推送通知
- node.js - 无法启动服务器
- spring-boot - SpringBoot 并使用/加载动态的“applicationContext.xml”而不是硬编码的
- go - 使用 aws-go-dep 安装无服务器不起作用
- c# - 无法使用 C# 使用自定义文件作为资源创建 MemoryStream
- sql-server - 在不知道表中内容的情况下映射列
- wpf - 如何使用资源字典删除 WPF 菜单中下拉菜单项周围的边框
- kafka-consumer-api - Spring Kafka过滤器不过滤消费者记录
- javascript - Testcafe - 测试多个页面