PDA

View Full Version : Connecting to MSSQL Database



weely
Aug 13th, 2007, 06:25 PM
Hello all,
I really need help. I am trying to connect PHP to a MSSQL database but I can't get it to connect. I'm using mssql_connect() and have supplied all the arguments but still no joy. Kindly help if u can as I have a deadline on the 17th of Agust 2007.

vinyl-junkie
Aug 13th, 2007, 08:11 PM
Are you sure you're using the correct parameters? Are they in the correct order?

weely
Aug 16th, 2007, 11:10 AM
this is an excerpt of my code:

$conn = mssql_connect("server_name", "username", "password");
mssql_select_db("database", $conn);

I tried printing the connection string to screen (echo $conn) but it gives a blank screen - which indicates an error because I have other echo statements on the page.

A colleague advised I should use:
putenv('TDSVER=70');

just before the mssql_connect() function. I have also tried this but still no joy.

vinyl-junkie
Aug 16th, 2007, 01:28 PM
Check your server log. You should be able to see your error message there.

Alternatively, instead of calling mssql_connect with hard-coded parameter values, assign values to variables for each of those parameters and use the variables as arguments for your function. Echo each of those variables prior to calling mssql_connect. For example:


$server = "server_name";
$user = "username";
$pwd = "password";

echo $server . "<br>";
echo $user . "<br>"
echo $pwd;

mssql_connect($server, $user, $pwd);

You might also change the above code to echo those variables one at a time, to perhaps further isolate the source of the problem.