0

new to laravel framework, I am running multiple database connections for a project I am working on. Just a simple test against one of the mysql instance,

<p>{{ $data2 = DB::connection('mysql2')->table('test')->get() }}</p>

gives a simple dump but when run simmilar test against the ms sql server 2012, it errors out

<p>{{ $data3 = DB::connection('sqlsrv')->table('test1')->get() }}</p>

The error is:

ErrorException in helpers.php line 519:
Method Illuminate\Support\Collection::__toString() must return a string value

my db config is similar to other examples I have seen posted online.

'sqlsrv' => [
        'driver' => 'sqlsrv',
        'host' => env('DB_HOST', 'SQL3.company.ca'),
        'database' => env('DB_DATABASE', 'test'),
        'username' => env('DB_USERNAME', 'test'),
        'password' => env('DB_PASSWORD', '#######'),
          'collation' =>  'SQL_Latin1_General_CP1_CI_AS',
          'charset'   =>  'latin1',
        'prefix' => '',
],

Did I set up something wrong? any direction I should be looking at?

4
  • your query returns an array and laravel looks for a string.. Commented Mar 14, 2017 at 21:56
  • you should run queries in your controller and return the results along with the view. look at this stackoverflow.com/a/26354972/4668162 Commented Mar 14, 2017 at 22:00
  • {{dd(DB::connection('sqlsrv')->table('test1')->get()) }} not goodif get data logic in view u should write model or controller Commented Mar 15, 2017 at 1:07
  • Thanks for the quick responses, I did manage a return with p>{{ $data4 = DB::connection('sqlsrv')->table('test1')->select(DB::RAW('username'))->get() }}</p> to the sql 2012 server, and I started testing/working on connection to the old sql 2005 server. Returned this morning, and the successful connection wasn't working anymore and getting the 'SQLSTATE[01002] Adaptive Server connection failed (severity 9)' so something I did last night or servers changed last night.. so much fun Commented Mar 15, 2017 at 23:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.