syedasimmeesaq
asked on
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
Thanks
ASKER
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
Thanks
ASKER
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
Thanks
ASKER
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
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
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
ASKER
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
<?php
$connect = mssql_connect("192.168.0.1
if ($connect) {
echo "WOO HOO";
}
?>
and it didn't connect. I am sure I am using the right password and username
Thanks
syedasimmeesag:
What output do you get from the above code? any error messages?
What output do you get from the above code? any error messages?
ASKER
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>
<!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>
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!";
}
ASKER
it says
error connecting
Thanks
error connecting
Thanks
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?
ASKER
I will check with the admin for the server again. I will have to call him. I will be writing back soon.
Thanks
Thanks
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:
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!";
}
ASKER
when I use the last code you sent me, noting shows on the page. Just a blank page.
Thanks
Thanks
ASKER
I am using this code
<?php
$conn = mssql_connect('server','us er','pass' ) or die(mssql_get_last_message ());
if($conn)
{
echo "Connected Successfully!";
}
else
{
echo "Connection Failed!";
echo mssql_error();
}
?>
<?php
$conn = mssql_connect('server','us
if($conn)
{
echo "Connected Successfully!";
}
else
{
echo "Connection Failed!";
echo mssql_error();
}
?>
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?
ASKER
I am not yet..I have made a call. What do u think why didn't the above code work?
Thanks
Thanks
ASKER
I have access to the sql server..is it anyway I can check it myself from tere instead of waiting on this guy?
Thanks
Thanks
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.
ASKER
ok I will write back here as soon as I get some info from this guy
Thanks
Thanks
ASKER
ok I got the confirmation about password and login and they were correct.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
No problem glad to help and glad you figured it out!
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.