This is a discussion on Php & mssql within the Coding Help forums, part of the Webmaster Discussion category; I've upgraded to PHP 5.2.6 and im running SQL Server Express 2005. Trying to get a simple query from the ...
| |||||||
| Register | Forum Rules | FAQ | Donate | Calendar | Search | Today's Posts | Mark Forums Read |
| |||||
| I've upgraded to PHP 5.2.6 and im running SQL Server Express 2005. Trying to get a simple query from the SQL server to display in a PHP page, i have the MSSQL module showing up in the phpinfo() page and im running the code below, its not givign any errors just keeps printing out the message i have put if for the 'or die' clause. Any ideas or help is always appreciated. PHP Code: Last edited by ziycon; 02-12-2008 at 01:41 AM.. |
| |||||
| did you try the server name as "localhost"
__________________ :. Web Design & Development Web Design Ireland :. Search Engines Optimization Search Engines Optimization :. Car Parts & Accessories Car Parts :. Cars Ireland Cars Ireland :. I Have 2 Find It Directory SEF Directory |
| ||||
| Hey, I don't have a lot of experience with PHP these days i am a C# Developer.. However you should be able to do a try / catch with your mssql_connect and then catch the exception. If you could do that and paste the exception here then it will give us much more detail as to what is happening. Cheers Dave
__________________ Web Design Ireland - CDG Web Design |
| |||||
| Doesn't make any difference. Quote:
|
| |||||
| try this [code <?php $link = mssql_connect ($servername,$dbusername,$dbpassword) or die(mysql_error().'Unable to connect to database.'); ?> [/code] |
| ||||
| What Louie has given looks to be exactly what you need to write out the exception. Give that a shot and post up the results till we see what's happening. |
| |||||
| Still only shows up the text i've entered into the 'die' clause, so confused!?! Last edited by ziycon; 01-12-2008 at 06:43 PM.. |
| ||||
| haha... no i don't think so. Can you try this example try { $hostname = "ADMIN\SQLEXPRESS"; $dbname = "testdb"; $username = "sa"; $pw = "adm1n"; $dbh = new PDO ("mssql:host=$hostname;dbname=$dbname","$username" ,"$pw"); } catch (PDOException $e) { echo "Connection failed because: " . $e->getMessage() . "\n"; exit; } That should write out your exception.. However someone of the PHP guys here may have a better way of doing it.. but that should work |
| |||||
| Figured it out after a good few hours, its pretty simple! I was using mssql instead of sqlsrv, i'll explain. Microsoft released a PHP/SQL 2005 driver for interaction so when this driver/extension is installed and instead of using the mssql_connect() you have to use sqlsrv_connect() as there is a whole new API for the MS driver available here API Reference (SQL Server 2005 Driver for PHP), the old way of connecting to SQL via PHP using the ntwdblib.dll file will not work on a SQL installation after SQL Server 7 as its deprecated, so you need to use SQL Server 2005 Driver for PHP Documentation from now on. Thanks for all your help lads! |
| Tags |
| mssql, php, sql |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| | ![]() | |||
| | ![]() | |||