lundi 18 juin 2018

Bad Gateway errors when trying to connect Laravel Homestead to sqlsrv database

I have been using Laravel v5 for a little while now, connecting to a homestead/vagrant virtual machine and integrating into a local MySQL database. However, I now need to connect remotely to a MSSQL database on my network via the same virtual machine.

Originally I was receiving driver not found errors when trying to use the sqlsrv connection, but I overcome that by installing the php7.1-sybase package. I can now confirm that php -m is indicating that pdo_dblib is installed and enabled.

I have setup the connection details in my .env file to use a second database connection:

DB_CONNECTION_SECOND=sqlsrv
DB_HOST_SECOND=<server>
DB_PORT_SECOND=1433
DB_DATABASE_SECOND=<database>
DB_USERNAME_SECOND=<username>
DB_PASSWORD_SECOND=<password>

I can successfully ping the server from my virtual machine.

Within my model, I have specified the $connection and $table parameters:

/**
 * The database name used by the model.
 *
 * @var string
 */
protected $connection = 'sqlsrv';

/**
 * The database table used by the model.
 *
 * @var string
 */
protected $table = '<tablename>';

And in my controller, I am simply trying to return a single record back using a where claus:

/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{



    $employees = Employee::where( 'LastName', '=', 'Bloggs' )->get();



    return $employees;



}

However, any connection that I try and make results in a 502 Bad Gateway error. I have also tried connecting to different databases on the network but I still get the same error.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire