3

PHP, Laravel, calling

$db->select("EXEC [dbo].[sp_StoredProc1] 1, 3, 1, '2016-06-12 00:00:00', '2016-09-12 00:00:00'");

RESULT - EMPTY ARRAY!!!

Calling the same function via SQL Server Management Studio:

EXEC [dbo].[sp_StoredProc1] 1, 3, 1, '2016-06-12 00:00:00', '2016-09-12 00:00:00'

RESULT - VALID TABLE.

Any idea, why this might happen is warmly appreciated

Alexey Abraham
  • 379
  • 2
  • 13

2 Answers2

3

The cause for this - is an ERROR in PHP PDO for MS SQL Server. Exception is not thrown despite happens. The very alike case is depicted here: http://www.sqlservercentral.com/Forums/Topic1754869-392-1.aspx

So it is sort of 2 step problems:

  1. When stored procedure parameters are not EXPLICITLY set to NULL/NOT NULL they are inherited, what causes exception...
  2. which is NOT Shown by PDO (the bug is in Laravel PDO).

Also, you might see this thread PHP - PDOException is not thrown on error, an empty array returned (SQL Server) My colleague did better investigation than me for this issue :)))

Community
  • 1
  • 1
Alexey Abraham
  • 379
  • 2
  • 13
0

Try this:

DB::select(DB::raw("EXEC [dbo].[sp_StoredProc1] 1, 3, 1, '2016-06-12 00:00:00', '2016-09-12 00:00:00'");

You can also try to see what you get when you but both the DB::select(...) part and just the DB::raw("...") part in a dd() die and dump function;

Markinson
  • 2,077
  • 4
  • 28
  • 56