We have a project developed by different teams. While using windows +. net + sqlserver2008; while using linux + yii (php) + mysql for development, now I want to use yii to connect to sqlserver. The system in the development environment is osx. How can I solve the connection problem? We have a project developed by different teams. Use
windows
+
.net
+
sql server 2008
The other side uses
linux
+
yii(php)
+
mysql
Development, now want to use
yii
Connect
sql server
The system in the development environment is
osx
, How to solve the connection problem?
Reply content:
We have a project developed by different teams. Usewindows
+.net
+sql server 2008
The other side useslinux
+yii(php)
+mysql
Development, now want to useyii
Connectsql server
The system in the development environment isosx
, How to solve the connection problem?
Http://www.yiiframework.com/doc/guide/1.1/en/database.dao#establishing...
It is the same as connecting to mysql.
If you connect to SQL server, you can change the dsn configuration.
$connection=new CDbConnection('mssql:host=localhost;dbname=testdb',$username,$password);
If the host is not on a machine, the host = SQL _server_host
Find some answers and record some problems.
Http://php.net/manual/zh/pdo.drivers.php
Currently, freeTDS and pdo_dblib are used, but the encoding is incorrect. Yii uses UTF-8 and SQL server uses gbk.
The osx configuration is as follows. An error is reported when utf8 is put down.
'api' => [ 'class' => 'yii\db\Connection', 'dsn' => 'dblib:host=x.x.x.x;dbname=dbname;charset=utf8', 'username' => 'username', 'password' => 'password', //'charset' => 'utf8', ],
The ubuntu configuration is as follows. The program runs normally when utf8 is put, but garbled characters are written into the SQL server.
'api' => [ 'class' => 'yii\db\Connection', 'dsn' => 'dblib:host=x.x.x.x;dbname=dbname;charset=utf8', 'username' => 'username', 'password' => 'password', //'charset' => 'utf8', ],
Encoding problem has been solved, see here: http://segmentfault.com/q/1010000002661362
After researching the problem, you will understand it. There are many ways to connect to SQL server in unix/linux, such as freetds + unixODBC (iODBC.
No matter which database is supported by php pdo, it is nothing more than the connection between the database drive and the database manager.
Php pdo link: http://php.net/manual/zh/pdo.drivers.php