'SET ANSI_WARNINGS ON' Laravel 5.4

1

I'm using Laravel 5.4 with 2 connections, one of them is just to access some Views of a Sql Server bank, and one of them does a LINKED SERVER which forces me to set some settings before making a query. p>

Today I can do this in my Controller as follows:

$busca = DB::connection('meuhost');
$busca->statement('SET ANSI_WARNINGS ON');
$busca->statement('SET ANSI_PADDING ON');
$busca->statement('SET ANSI_NULLS ON');

$select = $busca->select('SELECT top 100 * FROM nome_da_view ');

This works perfectly, but I did not like to work that way, so I created a Model to access this View that looks like this:

namespace App;

use Illuminate\Database\Eloquent\Model;

class NomeDaModel extends Model
{
    // 
    protected $connection = 'meuhost';

    protected $table = 'nome_da_view';

}

And no Controller:

$busca = NomeDaModel::get();

I have tried to set using setAttribute , statement, exec, nothing worked. The error occurs in the PDO:

exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 7405 General SQL Server error: Check messages from the SQL Server [7405] (severity 16) [(null)]

But we already know what needs to be set up on the connection to resolve this error, I just need to know the correct way to do this in Model or Controller other than the way it worked right up.

    
asked by anonymous 09.05.2017 / 18:30

0 answers