6
I’m creating an application that needs to connect to two different databases. A database I am creating (Mysql) and a database I received ready that I am only allowed to query (SQL Server). The purpose of the application is to query the data of the SQL Server database, make operations with this data and store them in the Mysql database
I’m very new to Laravel and I don’t know if it’s possible to work with both banks. Has anyone ever done it or knows if it works?
UPDATING:
I tried to do as I suggested link but makes a mistake.
Database file.php:
'default' => 'mysql',
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'matriculas',
'username' => '*****',
'password' => '*****',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => '10.31.24.2',
'database' => 'SIGA',
'username' => '******',
'password' => '*****',
'prefix' => '',
),
),
the Controller:
class MatriculasController extends BaseController{
public function formulario(){
$teste= DB::connection('sqlsrv')->select('select * from supervisor.PESSOA');
dd($teste);
}
}
The mistake:
Erro no servidor (500)
UPDATE 2:
I realized that the problem is with the driver "sqlsrv" that does not have on the server. The server is a Centos 6 with PHP 5.4.45. I don’t know how to install this driver for this version of PHP, I can’t find the corresponding RPM package. Does anyone have any idea what to do??
I think this article can help you: this one in English: http://fideloper.com/laravel-multiple-database-connections
– Gabriel Rodrigues
You wrote
conection
with an
only. It isconnection
.– Diego Souza
@Deesouza, really! But still gave problem, I wrote correctly and when loading the page appears "Error on the server (500)"
– Amanda Lima
This line is already set to true. It still shows no error. If I error the syntax or anything else shows the error correctly, in this case gives error on the server.
– Amanda Lima
Nothing appears :(
– Amanda Lima
Without the line
$teste= DB::connection('sqlsrv')->select('select * from supervisor.PESSOA');
works perfectly.– Amanda Lima
Yes, the name is exactly as I wrote in the query
– Amanda Lima
Works with Mysql
– Amanda Lima
From what I understand, these Xtensions are for windows. I’m using Linux. If it is because of the connection with Sqlserver, everything is ok, I have another application on the server that uses the mssql function and works fine.
– Amanda Lima
I found the problem, I will update the question.
– Amanda Lima
Managed to solve this problem, @Amandalima ?
– Diego Souza
I got it in "gambiarra" mode. I made my own connection class using mssql. I found that the sqlsrv driver does not work on the server I am working on and I have no way to change the version of PHP installed
– Amanda Lima
To install the driver, you only need to download it on the Microsoft website (php_sqlsrv_pdo and php_sqlsrv), save it in the PHP/ext folder, open the PHP configuration file, the
php.ini
, create a new referenceextension=php_sqlsrv_pdo
andextension=php_sqlsrv
. Restart the server.– StillBuggin