Hi,
i have to connect to sql server 2017 from Yii2.0 server Ubuntu 18.04.
can you help me?
Thanks
Hi,
i have to connect to sql server 2017 from Yii2.0 server Ubuntu 18.04.
can you help me?
Thanks
Hi, you can configure connection to your database in the file config/db.php
. Simply enter appropriate values like below
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=your.database-server.com;dbname=yii2basic',
'username' => 'user123',
'password' => 'password123',
'charset' => 'utf8',
];
More info here
Hi,
SQL SERVER not mysql.
I installa PDO Driver on ubuntu server?
I’m sorry but I have not any personal experience with sql server. But you could try to install mssql pdo driver following this guide https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15&viewFallbackFrom=sql-server-ver17
Check if the driver was installed correctly with phpinfo()
. There should be new mssql driver in the PDO section.
And then, change the driver string in the dsn
line:
'dsn' => 'mssql:host=your.database-server.com;dbname=yii2basic',
I haven’t tested this solution since I do not have access to any SQL Server. But you could try it and give feedback or you can wait for someone who actually have worked with Yii2 and SQL Server.
Thanks,
i test and update the post.
Have a nice day
Hi,
solved:
add in php.ini
extension=sqlsrv.so
extension=pdo_sqlsrv.so
restart apache
$row = Yii::$app->db2->createCommand(‘SELECT * FROM table_name’)->queryAll();
db2:
‘db2’ => [
'class' => 'yii\db\Connection',
'driverName' => 'sqlsrv',
'dsn' => 'sqlsrv:Server=10.10.10.79;Database=mydb',
'username' => 'sa',
'password' => 'sapsw',
'charset' => 'utf8'
]