Solved

Help making SQL server work with PHP

Posted on 2007-11-28
23
638 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]
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
syedasimmeesag:

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

Author Comment

by:syedasimmeesaq
Comment Utility
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
Comment Utility
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
Comment Utility
it says
error connecting

Thanks
0
 
LVL 21

Expert Comment

by:nizsmo
Comment Utility
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
Comment Utility
I will check with the admin for the server again. I will have to call him. I will be writing back soon.

Thanks
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 21

Expert Comment

by:nizsmo
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
ok I will write back here as soon as I get some info from this guy
Thanks
0
 
LVL 9

Author Comment

by:syedasimmeesaq
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
No problem glad to help and glad you figured it out!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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

11 Experts available now in Live!

Get 1:1 Help Now