using php with ms sql server
Moderator: General Moderators
using php with ms sql server
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
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
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: using php with ms sql server
You did not post the script.chopWood wrote:I'm using MAMP with php v. 5.2.11 with the following script
Sounds like you do not have the mssql library install in PHP. Typically you would uncomment the following line in php.ini:chopWood wrote:Fatal error: Call to undefined function mssql_connect() in /PhpSql/quickStart_Practice/phpPNEdevelopment/skiSwap/sqlConnect.php on line 10
extension=php_mssql.dll
(#10850)
Re: using php with ms sql server
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
thanks much
chop
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: using php with ms sql server
Christopher wrote:Typically you would uncomment the following line in php.ini:
extension=php_mssql.dll
(#10850)
Re: using php with ms sql server
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
thanks, Chop
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: using php with ms sql server
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
(#10850)
Re: using php with ms sql server
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
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
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: using php with ms sql server
Yes, change it from:
; extension=msql.so
To:
extension=msql.so
And then restart the web server
; extension=msql.so
To:
extension=msql.so
And then restart the web server
(#10850)
Re: using php with ms sql server
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
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
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: using php with ms sql server
Don't know if that is a type, but "extension=msql.so" is different than "extension=mssql.so".
(#10850)
Re: using php with ms sql server
I tried "msql" as a search string also and got nothing.
- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: using php with ms sql server
Chopwood,chopWood wrote:I tried "msql" as a search string also and got nothing.
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!
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: using php with ms sql server
"msql.so" is for a completely different database. It should be:chopWood wrote:I tried "msql" as a search string also and got nothing.
extension=mssql.so
Yes, see the manual.
(#10850)
Re: using php with ms sql server
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
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
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: using php with ms sql server
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.
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.
(#10850)