我正在使用Laravel 5.5重构一个Web应用程序,这里有一个原始查询,我需要将使用PHP从用户输入中获取的日期字符串转换为{{1}中的DATETIME
},以便将其与其他一些列进行比较。这是查询失败的一小部分:
Sql Server
我没有编写查询,我只是将其改编为Laravel原始查询以进行Web应用程序的重构(这很复杂,我不想使用查询生成器全部重写),这就是错误Laravel抛出:
SET NOCOUNT ON;
DECLARE @the_date DATETIME;
DECLARE @floor VARCHAR(10);
SET @the_date = (SELECT CONVERT(DATETIME, '?', 105));
SET @floor = '?' + '%';
SELECT fo_bs.SeatCir,
fo_bs.UserDAS,
fo_bs.FromDate,
fo_bs.ToDate,
fo_bs.Status
FROM BookedSeats fo_bs
WHERE fo_bs.FromDate <= @the_date
AND fo_bs.ToDate >= @the_date
AND fo_bs.SeatCir LIKE @floor
现在,如果我从错误(第3行)中复制整个SQL并将其粘贴到SQL Server Management Studio中并进行运行,它将完美地获取行,这就是为什么我如此困惑的原因。
Laravel的odb_driver中是否有可用的严格模式?我尝试设置
SQLSTATE[22007]: Invalid datetime format: 241 [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]
Conversion failed when converting date and/or time from character string. (SQLExecute[241] at ext\pdo_odbc\odbc_stmt.c:260)
(SQL: SET NOCOUNT ON; DECLARE @the_date VARCHAR(20); DECLARE @floor VARCHAR(10); SET @the_date = (SELECT CONVERT(DATETIME, '03-04-2019 00:04:00', 105)); SET @floor = 'OV6.' + '%'; SELECT fo_bs.SeatCir, fo_bs.UserDAS, fo_bs.FromDate, fo_bs.ToDate, fo_bs.Status FROM FlexibleOffice.dbo.BookedSeats fo_bs WHERE fo_bs.FromDate <= @the_date AND fo_bs.ToDate >= @the_date AND fo_bs.SeatCir LIKE @floor )
在'strict' => false
中进行我的连接配置,但运气不好。