Irish SEO,  Marketing & Webmaster Discussion

 

Php & mssql

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 ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Webmaster Discussion > Coding Help

Register Forum Rules FAQDonate Calendar Search Today's Posts Mark Forums Read



Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-12-2008, 03:22 PM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 461
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Thanks: 3
Thanked 0 Times in 0 Posts
ziycon will become famous soon enough
Send a message via MSN to ziycon
Default [SOLVED]Php & mssql

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:
<?
php  
'sa';
 = 
'adm1n';
 = 
'ADMINSQLEXPRESS';
 = 
'testdb';

 = 
mssql_connect (,,) or die('Unable to connect to database.');
?>
__________________
Irish Gaming Network

Last edited by ziycon; 02-12-2008 at 01:41 AM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 01-12-2008, 04:12 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,326
Nominated 7 Times in 5 Posts
Nominated TOTW/F/M Award(s): 2
Thanks: 0
Thanked 1 Time in 1 Post
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 01-12-2008, 04:13 PM
Coder
 
Join Date: Feb 2008
Posts: 45
Nominated 1 Time in 1 Post
Nominated TOTW/F/M Award(s): 1
Thanks: 0
Thanked 0 Times in 0 Posts
Solonox is on a distinguished road
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 01-12-2008, 04:51 PM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 461
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Thanks: 3
Thanked 0 Times in 0 Posts
ziycon will become famous soon enough
Send a message via MSN to ziycon
Default

Quote:
Originally Posted by louie View Post
did you try the server name as "localhost"
Doesn't make any difference.

Quote:
Originally Posted by Solonox View Post
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
Tried this but unable to figure out how to display the error as if it's a SQL error a try catch in the PHP code wont display the error!?!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 01-12-2008, 05:35 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,326
Nominated 7 Times in 5 Posts
Nominated TOTW/F/M Award(s): 2
Thanks: 0
Thanked 1 Time in 1 Post
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

try this
[code
<?php

$link = mssql_connect ($servername,$dbusername,$dbpassword) or die(mysql_error().'Unable to connect to database.');
?>

[/code]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 01-12-2008, 06:28 PM
Coder
 
Join Date: Feb 2008
Posts: 45
Nominated 1 Time in 1 Post
Nominated TOTW/F/M Award(s): 1
Thanks: 0
Thanked 0 Times in 0 Posts
Solonox is on a distinguished road
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 01-12-2008, 06:37 PM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 461
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Thanks: 3
Thanked 0 Times in 0 Posts
ziycon will become famous soon enough
Send a message via MSN to ziycon
Default

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..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 01-12-2008, 06:45 PM
Coder
 
Join Date: Feb 2008
Posts: 45
Nominated 1 Time in 1 Post
Nominated TOTW/F/M Award(s): 1
Thanks: 0
Thanked 0 Times in 0 Posts
Solonox is on a distinguished road
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9 (permalink)  
Old 02-12-2008, 01:41 AM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 461
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Thanks: 3
Thanked 0 Times in 0 Posts
ziycon will become famous soon enough
Send a message via MSN to ziycon
Default

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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10 (permalink)  
Old 02-12-2008, 01:50 PM
Coder
 
Join Date: Feb 2008
Posts: 45
Nominated 1 Time in 1 Post
Nominated TOTW/F/M Award(s): 1
Thanks: 0
Thanked 0 Times in 0 Posts
Solonox is on a distinguished road
Default

Ahh nice one man! Well glad ya got it sorted..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
mssql, php, sql

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Sponsored links

Pepperjam Network
Paid On Results www.zanox.com Get Chitika Premium


All times are GMT +1. The time now is 02:29 PM.


Powered by: vBulletin Version 3.8.4, Copyright ©2000 - 2010, Jelsoft Enterprises Limited.
Hosted in Ireland by Blacknight - Test your ISP |Irish Hosting Directory| Armchair.ie|Logo by Eden Web Design|Avatars by Afterglow |Latest Blog Entries | VPS HostingAd Management by RedTyger

Search Engine Friendly URLs by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64