Page 1 of 1
using php with ms sql server
Posted: Tue Jun 14, 2011 9:43 am
by chopWood
Generally, I'm looking for information on how to use php with a Microsoft sql db
Specifically:
I'm using MAMP with php v. 5.2.11 with the following script to get into a ms sql database but get the following error -
Fatal error: Call to undefined function mssql_connect() in /PhpSql/quickStart_Practice/phpPNEdevelopment/skiSwap/sqlConnect.php on line 10
Is there a way to add this function to my php library?
thanks for your help
Re: using php with ms sql server
Posted: Tue Jun 14, 2011 1:42 pm
by Christopher
chopWood wrote:I'm using MAMP with php v. 5.2.11 with the following script
You did not post the script.
chopWood wrote:Fatal error: Call to undefined function mssql_connect() in /PhpSql/quickStart_Practice/phpPNEdevelopment/skiSwap/sqlConnect.php on line 10
Sounds like you do not have the mssql library install in PHP. Typically you would uncomment the following line in php.ini:
extension=php_mssql.dll
Re: using php with ms sql server
Posted: Tue Jun 14, 2011 5:19 pm
by chopWood
Sorry I forgot the script but probably not necessary anyway as it was the line with mssql_connect() that gave the error, Can you give me instruction on how I can install the mssql library?
thanks much
chop
Re: using php with ms sql server
Posted: Tue Jun 14, 2011 10:28 pm
by Christopher
Christopher wrote:Typically you would uncomment the following line in php.ini:
extension=php_mssql.dll
Re: using php with ms sql server
Posted: Wed Jun 15, 2011 12:48 pm
by chopWood
I searched my php v. 5.2.11 for any string with "mssql". There is none so I believe I need to install the library as you mentioned. Can you point me in the right direction to do this?
thanks, Chop
Re: using php with ms sql server
Posted: Wed Jun 15, 2011 3:15 pm
by Christopher
In the php.ini file there is a setting to specify the extension directory and a place to load extensions (that is the line I provided above). I assume you are on a windows server since you are using mssql. The extension directory is in the php directory and should contain the file php_mssql.dll. Usually on windows, all of the extensions are listed and you just uncomment the ones you want
Re: using php with ms sql server
Posted: Wed Jun 15, 2011 5:32 pm
by chopWood
Thanks for the information. Actually, I'm using MAMP (as stated above) which is an application for Macintosh. I did follow your advice, however and found the following in the php.ini file on my MAMP system:
Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename.extension
;
; For example, on Windows:
;
; extension=msql.dll
;
; ... or under UNIX:
;
; extension=msql.so
;
; Note that it should be the name of the module only; no directory information
; needs to go here. Specify the location of the extension with the
; extension_dir directive above.
----------------- I'm thinking that the one I want to un-comment is extension=msql.so
Would you agree with this??
thanks again for your help... getting closer I think
Chop
Re: using php with ms sql server
Posted: Thu Jun 16, 2011 3:22 pm
by Christopher
Yes, change it from:
; extension=msql.so
To:
extension=msql.so
And then restart the web server
Re: using php with ms sql server
Posted: Thu Jun 16, 2011 6:03 pm
by chopWood
Okay, I un-commented the "extension=msql.so" and restarted the server. When I search "php info." for any reference to "mssql" I find nothing. Seems there should be some functions somewhere in the listing for mssql_etc.
If it has any meaning in this case. when I run the following"
<?php
print_r(PDO::getAvailableDrivers());
?>
the result is:
Array ( [0] => sqlite [1] => sqlite2 [2] => pgsql [3] => mysql )
Do I need some sort of driver installed?
I've been combing the web for days now and haven't found a clear answer to how I can use php to access Microsoft sql server. THough it seems it shouldn't be difficult I have found many diverse answers, some that don't agree with one another. I posted on the MAMP forum and got nothing at all in about 5 days. As if nobody has ever done this before.
thanks again
Chop
Re: using php with ms sql server
Posted: Thu Jun 16, 2011 8:00 pm
by Christopher
Don't know if that is a type, but "extension=msql.so" is different than "extension=mssql.so".
Re: using php with ms sql server
Posted: Fri Jun 17, 2011 9:10 am
by chopWood
I tried "msql" as a search string also and got nothing.
Re: using php with ms sql server
Posted: Fri Jun 17, 2011 12:25 pm
by flying_circus
chopWood wrote:I tried "msql" as a search string also and got nothing.
Chopwood,
I would start with the PHP documentation on the mssql extension, located
here.
alternatively, I did a quick google for "mamp mssql" and the first result confirms what Christopher is trying to help you with.
http://forum.mamp.info/viewtopic.php?f=2&t=5926
Good luck!
Re: using php with ms sql server
Posted: Fri Jun 17, 2011 4:01 pm
by Christopher
chopWood wrote:I tried "msql" as a search string also and got nothing.
"msql.so" is for a completely different database. It should be:
extension=mssql.so
Yes, see the manual.
Re: using php with ms sql server
Posted: Sun Jun 19, 2011 3:44 pm
by chopWood
I took a look at the php manual and some posts. I now have both MAMP and XAMPP on ny Mac. After searching the php info. in both these applications for relevant strings such as "extension=mssql.so" I found nothing. I even tried just adding it into the end of the php.ini file (after not having found a commented version of it).
1. Someone mentioned installing a product called "freetds"??
2. Someone suggested I invest $35 in an ODBC driver such as the one here:
https://www.actualtech.com/buynow.php
3. Someone also mentioned "You will have to 're-make' PHP and specify which modules to include." Though I don't know what is meant by "re-make".
I'm ready to jump at #2 as the company seems to focus on db connectivity for the Mac -Unless someone out there has a cheaper, not to complex solution I can try before whipping out my credit card.
thanks for your suggestions, CHop
Re: using php with ms sql server
Posted: Sun Jun 19, 2011 6:48 pm
by Christopher
There is also an OBDC driver distributed with PHP:
http://www.php.net/manual/en/book.uodbc.php
But $35 may be cheaper than the time it will take you to compile PHP (that is re-make). It is not difficult to compile PHP, your call.