lundi 1 février 2016

How to execute a multiple raw query using laravel?

I am using Laravel 5.2. I have a raw SQL statement that I like to execute.

Here is what I tried

DB::select( DB::Raw($sql) );

However, this works for the first query. If I execute another query in the same run I get the following error

FatalErrorException in Connection.php line 323: Cannot access empty property

So if I execute this

DB::select( DB::Raw($sql1) );

and then

DB::select( DB::Raw($sql2) );

How can I execute multiple queries in the same run time.

I will get an error. Do I need to reinitialize the DB class before I call the second query? if so how would I reset it?

UPDATED

dd( DB::raw($sql)  );

I get the following

Expression {#367 ▼
  #value: """
      SELECT TOP 1 '1'\n
    FROM survey_answer_defined\n
    INNER JOIN survey_answer_groups ON survey_answer_groups.id = survey_answer_defined.group_id\n
    WHERE survey_answer_groups.interview_id = '243' AND survey_answer_groups.control_id IN(300) AND 'E' IN('A','B','D','E')
    """
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire