Sometimes when calling SQL SP(Stored Procedure) from Laravel it shows the following exception.

SQLSTATE[HY000]: General error: 20018 Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options and then reissue your query. [20018] (severity 16) 

You can solve this exception from the SQL end or Laravel end. 


I think it's better and easier to solve from Laravel. So now we will see how to remove the exception from Laravel. First of all, see the existing SP call - 

$pdo = DB::connection('sql_db_config_name');
$pdo->select("EXEC SP_Sample");

Now we will call it differently, for this, we have to write the following code

$pdo = DB::connection('sql_db_config_name');
$pdo->select('SET ANSI_WARNINGS ON');        
$pdo->select('SET ANSI_NULLS ON');
$data  = $pdo->select("EXEC SP_Sample");

Here we add only the 2nd and 3rd lines to solve the problem. I hope this way the exception will solve.