Yii Framework Forum: MSSQL Database - Yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

MSSQL Database - Yii Database Connection (How) Rate Topic: -----

#1 User is offline   draven 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 08-February 12

Posted 08 February 2012 - 10:38 AM

..Hi :) ...Im new in using Yii Framework and recently I found it very interesting..

..HOwever, I was wondering, is it possible to connect a MSSQL Database with Yii.??

..If so...then could anyone please tell me how....
0

#2 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,608
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 08 February 2012 - 04:51 PM

Welcome to the forum.

From a windows box you should be able to use a config similar to this one. Ensure that you have an appropriate driver installed e.g. php_pdo_sqlsrv_53_nts_vc9.dll.
  'db'=>array(
    'connectionString' => "sqlsrv:server=localhost\SQLEXPRESS;database=some-database",
    'username' => 'some-username',
    'password' => 'some-password',
  ),

(Also, there is a number of existing MS SQL discussions in the forum)

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#3 User is offline   draven 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 08-February 12

Posted 08 February 2012 - 10:31 PM

..ok...I already got all the .dll files you said....


..But I still don't know where to place all these files...

..Im using "xampp"...
0

#4 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,608
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 09 February 2012 - 06:48 AM

I used this driver trying out an IIS-based installation. Don't know exactly what XAMPP will need (my current XAMPP bundled PHP seems to be too old for this driver).

Generally speaking, drivers goes into the php/ext/ subfolder. You will have to add a line to php.ini similar to
extension=php_pdo_sqlsrv_53_nts_vc9.dll

(It's also possible to store the driver elsewhere and specify a path)

I guess we have other forum users able to tell you exactly what to do. I also suggest you search the forum for additional MS SQL/XAMPP hints.

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#5 User is offline   Suralc 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 10-January 12

Posted 09 February 2012 - 12:45 PM

It`s very easy and most stuff was already said, but afaik xampp php was compiled with vc6 up to version 1.7.4 here, so if you are below that version you have to use the ts_vc6dll.

So you´d need to use the php_pdo_sqlsrv_53_ts_vc6.dll downloadable at microsoft/download/en/details.aspx?id=20098 . If you have chosen the correct path during installation (X:\...\...\php\ext) you just have to add

;extension=php_sqlsrv_53_ts_vc6.dll ; Procedual Interface
extension=php_pdo_sqlsrv_53_ts_vc6.dll


into your php.ini`s extension section. (Restart PHP after that)

btw. I never worked with sqlsrv+yii, so I never looked up, if yii even supports sqlsrv, just had some other projects using mssql but not yii
0

#6 User is offline   draven 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 08-February 12

Posted 12 February 2012 - 01:36 AM

..Well...I've tried reading some forums regarding to this....I also followed all the suggested solutions...I already have the drivers I need (I supposed)...and put it where it should be placed..

..However, I still got this error...



...what should I do now..??..Attached File  Capture.PNG (31.98K)
Number of downloads: 14
0

#7 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,608
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 12 February 2012 - 04:23 AM

View Postdraven, on 12 February 2012 - 01:36 AM, said:

...what should I do now..??..Attachment Capture.PNG


It seems like the db component part of your configuration file (protected/config/main.php) doesn't take effect. If this doesn't help you out, show us the file content.

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#8 User is offline   draven 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 08-February 12

Posted 12 February 2012 - 07:28 AM

...This is the "main.php" file of my project...Attached File  main.php (2.35K)
Number of downloads: 8


...
0

#9 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,608
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 12 February 2012 - 08:31 AM

View Postdraven, on 12 February 2012 - 07:28 AM, said:

...This is the "main.php" file of my project...Attachment main.php


1. You define the db config twice. Comment out the first one (sqlite).
2. Note the driver name in this post.

HTH (I didn't try it myself under XAMPP). At least you should see a different error message.

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#10 User is offline   draven 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 08-February 12

Posted 15 February 2012 - 10:56 AM

...oh hi again...I've got this error while trying to create a model in 'giic'Attached File  Capture.PNG (47.38K)
Number of downloads: 9

...I just want to know what is this error?
0

#11 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,608
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 15 February 2012 - 01:50 PM

Looks like you modified the framework source and forgot about it. You don't need to (and should not) modify the framework.

Reinstall the framework files, run yiic webapp, then enter the correct connection string and db credentials in the config file. Enter a password for Gii (there's nothing such as giic). Access the database creating a model. That's it.

Of course you have debug enabled in the start script index.php.

If no luck, check with phpinfo that you have the sqlsrv driver loaded. (You may encounter an error message suggesting you'll have to download and install an additional driver. At least I had to do that for my XP box.)

/Tommy

This post has been edited by tri: 15 February 2012 - 02:03 PM

Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
1

#12 User is offline   draven 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 08-February 12

Posted 21 February 2012 - 07:26 AM

..after doing some configuration in my xampp server..I finally got sqlsrv installed and got this result Attached File  1.PNG (9.32K)
Number of downloads: 9

..and here's the protected\config\main.php Attached File  main.php (2.48K)
Number of downloads: 5

..but i still got this error while trying the model generator in gii tool Attached File  2.PNG (38.3K)
Number of downloads: 9


..oh my, what else do i missed..??..
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users