Help making SQL server work with PHP

I have windows 2003 server. I downloaded a wamp and now i use apache as webserver for php pages. I am using mysql but for some reason now I have to connect to MSSQL 2005 server. MS SQL server 2005 is currently running smoothly on the same machine. Now when I do phpinfo() i don't see any MSSQL in the information. What can I do to make it work. I know I have to change the ini file in php and exclude the comments for mssql but I am looking for something in more detail for example if I need to download and .dll files or extensions for php.

Thanks
LVL 9
syedasimmeesaqAsked:
Who is Participating?
 
nizsmoConnect With a Mentor DeveloperCommented:
If the guy you are talking about is correct, and your password and username are correct, then your server address is probably the problem. Are you sure you have the right server address?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
check out this:
http://php.net/mssql

in short
<...>
The extension requires the MS SQL Client Tools to be installed on the system where PHP is installed. The Client Tools can be installed from the MS SQL Server CD or by copying ntwdblib.dll from \winnt\system32 on the server to \winnt\system32 on the PHP box. Copying ntwdblib.dll will only provide access through named pipes. Configuration of the client will require installation of all the tools.
<...>

and:
The MSSQL extension is enabled by adding extension=php_mssql.dll to php.ini.
0
 
syedasimmeesaqAuthor Commented:
Angelll I read this before, but what I don't understand I guess is the php box is same as where the sqlserver is. So in that scenario what am I suppose to do. There is no folder in my machine that is \winnt\system32, I however has this C:\WINDOWS\system32? Sould I copy the file from php\dll folder where it is currently reside to C:\WINDOWS\system32?

Thanks
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
syedasimmeesaqAuthor Commented:
I just copied ntwdblib.dll to windows\system32 directory and took out the comment ; and made sure extension=php_mssql.dll is in php.ini file. But when I ran phpinfo() it still doesn't show mssql
Thanks
0
 
syedasimmeesaqAuthor Commented:
ok mssql server shows up in the phpinfo() after I restarted the web server .
This is what I have.
mssql
MSSQL Support      enabled
Active Persistent Links       0
Active Links       0
Library version       7.0

Directive      Local Value      Master Value
mssql.allow_persistent      On      On
mssql.batchsize      0      0
mssql.compatability_mode      Off      Off
mssql.connect_timeout      5      5
mssql.datetimeconvert      On      On
mssql.max_links      Unlimited      Unlimited
mssql.max_persistent      Unlimited      Unlimited
mssql.max_procs      Unlimited      Unlimited
mssql.min_error_severity      10      10
mssql.min_message_severity      10      10
mssql.secure_connection      Off      Off
mssql.textlimit      Server default      Server default
mssql.textsize      Server default      Server default
mssql.timeout      60      60

doesthat mean that I will be able to connect to mssql now? can someone let me know of a script that I can run to see if that works.

Thanks
0
 
syedasimmeesaqAuthor Commented:
I tried a code to connect to the server using this

<?php
$connect = mssql_connect("192.168.0.1", "user", "pass") or die("it doesn't work");
if ($connect) {
   echo "WOO HOO";
}
?>
and it didn't connect. I am sure I am using the right password and username

Thanks
0
 
nizsmoDeveloperCommented:
syedasimmeesag:

What output do you get from the above code? any error messages?
0
 
syedasimmeesaqAuthor Commented:
I don't get any errors. I tried to use this code to get an error but it shows a blank page too

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Lab Page</title>
</head>

<body>
<?

error_reporting (E_ALL & ~E_NOTICE);

if ($dbc = mssql_connect ('server','user','pass')) {print '<p>Successfully connected to MSSQL.</p>';
mssql_close();

} else {
print '<p>Could not connect to MSSQL.</p>'echo mssql_error();
}

?>
</body>
</html>
0
 
nizsmoDeveloperCommented:
try this, see if you get any output
<?php
 
$conn = mssql_connect('server','user','pass') or die("Error connecting");
 
if($conn)
{
    echo "Connected Successfully!";
}
else
{
    echo "Connection Failed!";
}

Open in new window

0
 
syedasimmeesaqAuthor Commented:
it says
error connecting

Thanks
0
 
nizsmoDeveloperCommented:
then you seem to have a problem with either your server address, or your username and password. Are you able to check and verify your parameters?
0
 
syedasimmeesaqAuthor Commented:
I will check with the admin for the server again. I will have to call him. I will be writing back soon.

Thanks
0
 
nizsmoDeveloperCommented:
syedasimmeesaq,

Just to be clearer, your setup has no problems, as you are calling mssql_connect correctly, and it is NOT producing an error similar to "Call to undefined function mssql_connect..." which suggests your extensions are working fine.

This narrows it down to incorrect server address, password or username combination.

You can also give below a try:
<?php
 
$conn = mssql_connect('server','user','pass') or die(mssql_get_last_message());
 
if($conn)
{
    echo "Connected Successfully!";
}
else
{
    echo "Connection Failed!";
}

Open in new window

0
 
syedasimmeesaqAuthor Commented:
when I use the last code you sent me, noting shows on the page. Just a blank page.
Thanks
0
 
syedasimmeesaqAuthor Commented:
I am using this code
<?php
 
$conn = mssql_connect('server','user','pass') or die(mssql_get_last_message());
 
if($conn)
{
    echo "Connected Successfully!";
}
else
{
    echo "Connection Failed!";
      echo mssql_error();
}

?>
0
 
nizsmoDeveloperCommented:
Ok weird, but I am still convinced there is something wrong with either your server name, password or username. Are you able to verify those?
0
 
syedasimmeesaqAuthor Commented:
I am not yet..I have made a call. What do u think why didn't the above code work?
Thanks
0
 
syedasimmeesaqAuthor Commented:
I have access to the sql server..is it anyway I can check it myself from tere instead of waiting on this guy?
Thanks
0
 
nizsmoDeveloperCommented:
I think it is due to you having either the incorrect password, username or server address. Unfortunately you will need the details before you can connect to the server.
0
 
syedasimmeesaqAuthor Commented:
ok I will write back here as soon as I get some info from this guy
Thanks
0
 
syedasimmeesaqAuthor Commented:
ok I got the confirmation about password and login and they were correct.
Thanks
0
 
syedasimmeesaqAuthor Commented:
ok got it working with the combination of your instructions and some other steps I had taken

I went to SQL configuration and changed the tcp/ip to enabled then I also downloaded new ntw.....dll to both system32 and to php. server was ok on localhost. got connected successfully.

Thanks for your support and prompt responses.
Cheers
0
 
nizsmoDeveloperCommented:
No problem glad to help and glad you figured it out!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.