Forum Home
Press F1
 
Thread ID: 108189 2010-03-17 08:45:00 PHP MS SQL - Shouldn't this be working :S WarNox (8772) Press F1
Post ID Timestamp Content User
868076 2010-03-17 08:45:00 Hey!

Just trying to establish a connection between PHP and MS SQL 2008. This is the code I have, but I cannot get this to work. Although on the same server PHPBB is working fine.


<?php

//database connection
$server = "localhost";
$userName = "sa";
$pwd = "xxyyxxyy";
$db = "website";

//connection to the database
//$dbhandle = mssql_connect($server, $userName, $pwd);
$dbhandle = mssql_connect('localhost', 'sa', 'xxyyxxyy');
if (!$dbhandle){
echo "Couldn't connect to SQL Server on $myServer";
}

echo "hello";

//select a database to work with
$selected = mssql_select_db($db, $dbhandle);
if (!$dbhandle){
echo "Couldn't open database $myDB";
}

mssql_close($dbhandle);
?>

It doesn't even print out the 'hello', meaning the code doesn't get that far. Anyone have any idea why? As you can see I've tried using variables as well as entering the values directly for mssql_connect().

Thanks in advance.
WarNox (8772)
868077 2010-03-17 10:25:00 I'm assuming you've checked the username, password and database are correct hueybot3000 (3646)
868078 2010-03-17 10:58:00 Yes, I figure if any of those were wrong I'd at least get an error? WarNox (8772)
868079 2010-03-17 11:02:00 Have you tried setting the host rather than just locahost? hueybot3000 (3646)
868080 2010-03-17 13:14:00 Yes, I figure if any of those were wrong I'd at least get an error?
What error reporting mask are you using, and how are you checking for errors?
Erayd (23)
868081 2010-03-17 18:54:00 What you see above is all I have, but the code doesn't seem to get past:


$dbhandle = mssql_connect('localhost', 'sa', 'xxyyxxyy');
if (!$dbhandle){
echo "Couldn't connect to SQL Server on $myServer";
}


---

I will try setting the actual hostname or IP and let you know how that goes.
WarNox (8772)
868082 2010-03-17 18:59:00 Are you looking at the generated HTML for the error, or is the webserver logging it to a file somewhere? MushHead (10626)
868083 2010-03-17 19:17:00 Just an HTML error.

Its as if it doesn't know what mssql_connect() is. I've edited the php.ini file and uncommented the two extension lines:


extension=php_mssql.dll
extension=php_pdo_mssql.dll

is there anything else I need to do? or a way to see the logs?

Thanks again.

---

Oh and I've tried using the hostname/IP address but still not working.
WarNox (8772)
868084 2010-03-17 19:34:00 Disable your firewall and antivirus. nate (15033)
868085 2010-03-17 19:57:00 Dumb question probably, but whats your config.php file for phpbb I am assuming you are using mssql for that as well Morgenmuffel (187)
1 2 3 4