Yii2-linux, mac, php connection to SQL server problems

Source: Internet
Author: User
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 2008The other side uses linux+ yii(php)+ mysqlDevelopment, now want to use yiiConnect sql serverThe 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 2008The other side useslinux+yii(php)+mysqlDevelopment, now want to useyiiConnectsql serverThe 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.