Solved

Help making SQL server work with PHP

Posted on 2007-11-28
23
639 Views
Last Modified: 2013-12-12
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
0
Comment
Question by:syedasimmeesaq
  • 14
  • 8
23 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20369339
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
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 20369425
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
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 20369511
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
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 20369581
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
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 20369639
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
 
LVL 21

Expert Comment

by:nizsmo
ID: 20369723
syedasimmeesag:

What output do you get from the above code? any error messages?
0
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 20369748
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
 
LVL 21

Expert Comment

by:nizsmo
ID: 20369776
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
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 20369816
it says
error connecting

Thanks
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20369821
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
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 20369842
I will check with the admin for the server again. I will have to call him. I will be writing back soon.

Thanks
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 21

Expert Comment

by:nizsmo
ID: 20369892
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
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 20370718
when I use the last code you sent me, noting shows on the page. Just a blank page.
Thanks
0
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 20370724
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
 
LVL 21

Expert Comment

by:nizsmo
ID: 20370733
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
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 20370751
I am not yet..I have made a call. What do u think why didn't the above code work?
Thanks
0
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 20370776
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
 
LVL 21

Expert Comment

by:nizsmo
ID: 20370782
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
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 20370788
ok I will write back here as soon as I get some info from this guy
Thanks
0
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 20371098
ok I got the confirmation about password and login and they were correct.
Thanks
0
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 20371123
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
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 20371208
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
 
LVL 21

Expert Comment

by:nizsmo
ID: 20371406
No problem glad to help and glad you figured it out!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now