gream0604 Posted May 30, 2012 Posted May 30, 2012 Hello all, Having some problems getting PHP to connect to my MSSQL database. I am trying to write an application in PHP that needs to connect to a MSSQL database. I am running PHP5.3.1, and IIS for the web part SQL Express. Can anyone help me in the configuration of the PHP side of things? I have read a few articles and am very confused?
hit Posted May 30, 2012 Posted May 30, 2012 Meh, I replied before and then re-read your post which made mine look stupid so I deleted it, so let's start again! which bit of the configuration do you need help with? Is it actual PHP code to make a connection or configuration of IIS?
gream0604 Posted May 30, 2012 Author Posted May 30, 2012 Hi there, Thats okay. I have got the code to make to connection to the database, but i have read that you need to move DLL files, and change the php.ini config to get it working? Matt
hit Posted May 30, 2012 Posted May 30, 2012 It sounds like you are using a third party php application, if so, which one? I haven't usually needed to move anything around, just make sure everything is registered properly. So, let's get started: Which version of IIS are you using and on what server? Is the sqlexpress instance the only one on the machine and does its use default ports? Can you log in to the sqlexpress instance with Mssql management studio? Is the IIS service running? If so can you get a PHPINFO() page to run in the default site?
gream0604 Posted May 30, 2012 Author Posted May 30, 2012 It sounds like you are using a third party php application, if so, which one? I haven't usually needed to move anything around, just make sure everything is registered properly. So, let's get started: Which version of IIS are you using and on what server? Is the sqlexpress instance the only one on the machine and does its use default ports? Can you log in to the sqlexpress instance with Mssql management studio? Is the IIS service running? If so can you get a PHPINFO() page to run in the default site? Hiya, Im not using a third party application. Just IIS with the PHP extensions installed. In answer to your questions IIS is version 6, and is on a windows server 2003 server. Yes it is the only SQL instance, and i can log into it with the managment studio. Yes IIS is running, and yes i can get the phpinfo to run. Matt
hit Posted May 30, 2012 Posted May 30, 2012 (edited) Hi Matt, so, OK everything sounds like its running OK, is there a sqlsrv section in the output from the PHPINFO? If there is then everything should be good to go! What do you get if you run the following? $server = 'SERVER\INSTANCE'; //*Connect to MSSQL $link = mssql_connect($server, 'USERNAME', 'PASSWORD'); if (!$link) { die(''); } ?> You can also try to replace 'SERVER\INSTANCE' with 'IPADDRESS,PORT'. Edited May 30, 2012 by hit
gream0604 Posted May 30, 2012 Author Posted May 30, 2012 Hi there, I get the follwoing when i run that code: Parse error: parse error in C:\DFSRoots\NewVis\Network\info.php on line 2 Also there is no sqlsrv section in the phpinfo??
hit Posted May 30, 2012 Posted May 30, 2012 Ahh, just looked back and noticed server 2003 + PHP 5.3. SQLSRV isnt available for 2003, only vista, 7 and 2008. The old MSSQL driver and commands were taken out from PHP 5.3 and above. Not really sure where to go from here for you apart from using an earlier version of PHP or using server 2008. I would go with the latter if you can. Sorry!
gream0604 Posted May 30, 2012 Author Posted May 30, 2012 Ahh thats a real shame. I dont think i can really go back to a later version of PHP, and there is definatly not an option to move it over to server 2008. Looks like i am stuck then unless anyone has any other ideas? Looking at the overall picture, this is what i am trying to do: We have lansweeper running on a sevrer, and i am basically trying to pull some data from the lansweeper database, to display in my PHP application. If anyone knows of any other way to do this, then that would be a great help!
gream0604 Posted May 30, 2012 Author Posted May 30, 2012 Just been doing a bit of googleing, and have come across this. Do you think it might work? MSSQL Driver for PHP5.3 | Abby and Win's Blog
hit Posted May 30, 2012 Posted May 30, 2012 Looking here System Requirements (Microsoft Drivers for PHP for SQL Server) it appears that you may be in luck with the version 2 of the driver. Looks like you are back on track
gream0604 Posted May 30, 2012 Author Posted May 30, 2012 Ahh fantastic. I will give that a go at work tomorrow. Thanks for all your help, and i will let you know how i get on!!
gream0604 Posted May 31, 2012 Author Posted May 31, 2012 Hi All, Okay. Got in this morning, and this is the first thing i got to work on! I followed the instructions, and dowloaded v2.0 of the driver. I put the dll file in the ext directory, and am now getting the following error message when i restart IIS ... PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\ext\php_sqlsrv_53_nts_vc9.dll' - The specified module could not be found. I have double checked, and the file is there, and have also double checked the spelling the php.ini. All seems to be correct?? Any ideas? Matt
gream0604 Posted May 31, 2012 Author Posted May 31, 2012 Hiya, Finally got it working, by trying every version of the driver that was in the package that i downloaded. Turns out that the correct file is the php_sqlsrv_52_ts_vc6.dll
hit Posted May 31, 2012 Posted May 31, 2012 Hiya, Finally got it working, by trying every version of the driver that was in the package that i downloaded. Turns out that the correct file is the php_sqlsrv_52_ts_vc6.dll Excelent stuff, will have to remember this for myself!
gream0604 Posted May 31, 2012 Author Posted May 31, 2012 Okay. I am now having trouble on the coding part now! This is the code that i have got: $serverName = "01itserver\SQLEXPRESS"; //serverName\instanceName $connectionInfo = array( "Database"=>"lansweeperdb", "UID"=>"networktest", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo); $result = sqlsrv_query( $conn, 'select * from dbo.tblcomputers where computer = (PPS4)') $row = sqlsrv_fetch_assoc($result); echo($row['Computer']); ?> And i am getting the following error message: Parse error: parse error in C:\DFSRoots\NewVis\Network\test.php on line 7 Any ideas??
Willott Posted May 31, 2012 Posted May 31, 2012 (edited) Missing a ; at the end of the $result line I think I'd also stick a conditional check to ensure you're getting a result back before trying to fetch_assoc, just incase there's nothing there at some point and you get an error instead. Edited May 31, 2012 by Willott
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now