Use SQL SERVER 2000, the date format not like: yyyy/mm/dd hh:mm:ss. So I change to use SQL SERVER 2008 EXPRESS.
download PDO MS EXT
Install the Microsoft SQL Server 2008 R2 Native Client
Please read: System Requirements (Microsoft Drivers for PHP for SQL Server)
- read the manual, copy .dll to PHP Ext Dir, and enable this EXT in php.ini.
example:
- PHP 5.3.5 use: [php_pdo_sqlsrv_53_ts_vc6.dll] [php_sqlsrv_53_ts_vc6.dll]
- PHP 5.3.6 use: [php_pdo_sqlsrv_53_ts_vc9.dll] [php_sqlsrv_53_ts_vc9.dll]
Note: If you are using WAMP use the thread safe (ts) version
- Update your web main config. like this.
// PDO MSSQL
'db'=>array(
// 'class'=>'application.components.MyMsSqlConnection',
// old MS PDO + MSSQL 2000:
//'connectionString' => 'mssql:host=HOSTNAME\SQLEXPRESS;dbname=Client',
// new MS PDO + MSSQL 2005 2008
'connectionString' => 'sqlsrv:Server=HOSTNAME\SQLEXPRESS;Database=Client',
'username' => 'sa',
'password' => '111',
'charset' => 'GB2312',
'tablePrefix' => 'tbl_',
),
I love YII
My example : SQL Server 2005 and WampServer
I am running WampServer on Win7, and have SQL Server 2005 to connect to, as verified by DOS command:
~~~
sqlcmd -S TheSQLserver -E -d MyDataBaseName -Q "select @@version"
~~~
I installed 'sqlsrv' (i.e. "Microsoft Drivers 3.0 for PHP for SQL Server" found from the link you give above) - which required the 'SQL Native Client' add-on too.
Following the _SQLSRVHelp.chm instructions I copied the DLLs into C:\wamp\bin\php\php5.3.13\ext and added the following DLL names in the block of extension definitions in my C:\wamp\bin\apache\apache2.2.22\bin\php.ini (easily edited from WampServer's menu), so that PHP would understand 'sqlsrv' :
A test script had no success logging in with Windows Authentication, because my Apache httpd.exe service was running as user 'SYSTEM' by default. So I changed the service to run as my login id, and it now connects without having to specify user and password in the php file. (Servicing php http requests, Apache will always be connecting as me, even if I put my workstation server online and allow other users to connect via me)
My now functional test script (displays a whole small SQL table in HTML) contains these lines (amongst others) :
$serverName = 'TheSQLserver'; $connectionInfo = array( 'Database'=>'MyDataBaseName'); // , "ReturnDatesAsStrings" => true); well worth knowing! /* Connect using Windows Authentication. No User or Pwd required */ $conn = sqlsrv_connect( $serverName, $connectionInfo);
I then set about starting a test Yii application, using DOS command yiic webapp appname
Again, no user or password is required. My app's main.php just contains one item in the db array :
'db'=>array( 'connectionString' => 'sqlsrv:server=TheSQLserver;database=MyDataBaseName', //'username' => 'sa', //'password' => '***', ),
This has allowed me to get as far as running gii today, and successfully generating a model for one of my tables.
Problem in GII with conection SQL SERVER
I have a problem,
CDbConnection failed to open the DB connection: SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver 11 for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712
My main is:
// PDO MSSQL
'db'=>array(
'connectionString' => 'sqlsrv:Server=HOST;Database=XXX',
'emulatePrepare' => false,
'username' => 'XXX',
'password' => 'XXX',
'charset' => 'UTF8',
),
In requirements, my drive is ok:
PDO MSSQL extension (pdo_sqlsrv) -> OK -> Required for MSSQL database with the driver provided by Microsoft.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.