By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,586 Members | 623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,586 IT Pros & Developers. It's quick & easy.

PHP MSSQL connection problem.

P: n/a
mj
Hello, thanks for the help.

I am running a WinXP Pro w/ SP2 (my home computer, with ZoneAlarm
firewall)

Apache 2.0.52
MySQL 4.1.7
PHP 5.1.0-dev

I have developed a PHP/MySQL web app that tracks jobs for me, and we
use it on our peer-to-peer network. This program works GREAT :)

I also have a company website hosted remotely, where clients can place
a job request.

Win2k
IIS
MS SQL Sever 2000

On this web site we have a MSSQL database that records all the jobs
that where placed through the web site.

What I what to do know is connect to the remote MSSQL server and run
some SELECT statements with PHP.

NOW ... I can connect to the remote MS SQL sever with the client tools,
Enterprise Manager, and I can setup and connect with ODBC.

What I can't do is get php to connect to it.

- I have ntwdblib.dll in my c:\windows\system32 & c:\apache2\bin &
c:\php folders (year 2000 version)

- In SQL Sever Client Network Utility I only have TCP/IP as an "Enabled
protocols"

- I have extension=php_mssql.dll in my php.ini

- when I run:

function_exists('mssql_connect');

it returns true so I know that php_mssql.dll loaded OK

This is the code I try and connect with:

<?php

$host="mssql.dumbname.net";
$user="user";
$password="password";

mssql_connect($host,$user,$password) or die ("could not connect to
server"); // <-------- It always dies here. :(

mssql_select_db("trtrades") or die ("could not connect to DB");

....
?>

I know that the $host, $user, and $password are right because I can
connect to the remote DB with the client tools.
I also tried connect using php's ODBC functions:( I have already
created the DNS that is need)

odbc_connect($host,$user,$password) or die("can not connect to sever");
// <--------- This always dies as well

and still know luck ...
I have been working at this for a few days now, and searched all over
the net and groups for a solution to my problem with no luck.

I hope that someone might be able to help.

Cheers;

VanMan

Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
mj@lightfootarts.com wrote:
Hello, thanks for the help.

I am running a WinXP Pro w/ SP2 (my home computer, with ZoneAlarm
firewall)

Apache 2.0.52
MySQL 4.1.7
PHP 5.1.0-dev

I have developed a PHP/MySQL web app that tracks jobs for me, and we
use it on our peer-to-peer network. This program works GREAT :)

I also have a company website hosted remotely, where clients can place
a job request.

Win2k
IIS
MS SQL Sever 2000

On this web site we have a MSSQL database that records all the jobs
that where placed through the web site.

What I what to do know is connect to the remote MSSQL server and run
some SELECT statements with PHP.

NOW ... I can connect to the remote MS SQL sever with the client tools,
Enterprise Manager, and I can setup and connect with ODBC.

What I can't do is get php to connect to it.

- I have ntwdblib.dll in my c:\windows\system32 & c:\apache2\bin &
c:\php folders (year 2000 version)

- In SQL Sever Client Network Utility I only have TCP/IP as an "Enabled
protocols"

- I have extension=php_mssql.dll in my php.ini

- when I run:

function_exists('mssql_connect');

it returns true so I know that php_mssql.dll loaded OK

This is the code I try and connect with:

<?php

$host="mssql.dumbname.net";
$user="user";
$password="password";

mssql_connect($host,$user,$password) or die ("could not connect to
server"); // <-------- It always dies here. :(

mssql_select_db("trtrades") or die ("could not connect to DB");

...
?>

I know that the $host, $user, and $password are right because I can
connect to the remote DB with the client tools.
I also tried connect using php's ODBC functions:( I have already
created the DNS that is need)

odbc_connect($host,$user,$password) or die("can not connect to sever");
// <--------- This always dies as well

and still know luck ...
I have been working at this for a few days now, and searched all over
the net and groups for a solution to my problem with no luck.

I hope that someone might be able to help.

Cheers;

VanMan


What kind of error message do you get from your connect attempts (other
than the die messages)? Did you check the user notes in the
documentation (http://www.php.net/manual/en/functio...-connect.php)?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '05 #2

P: n/a
mj
Thanks for the reply Jerry. Yes I have readed ALL the user notes, and
every group I can find on this issue. I believe that other people have
had the same problem, and I followed the steps they tool to fix it ...
but still no luck :(

I don't get any kind of error message. For example when I run this
code:

<?php

....

$connt = mssql_connect($host,$user,$password);

if(!$connt)
{
$msg = mssql_get_last_message();
echo $msg;
}

....
?>

$msg if NULL.

Is there any way to tell if my mssql_connect() function is actual going
out to the remote sever and trying to connect? OR if the function is
failing on the local end?

also, these are my MSSQL setting in my php.ini file

mssql.allow_persistent = On
mssql.max_persistent = -1
mssql.max_links = -1
mssql.min_error_severity = 10
mssql.min_message_severity = 10
mssql.compatability_mode = On
;mssql.connect_timeout = 5
;mssql.timeout = 60
;mssql.textlimit = 4096
;mssql.textsize = 4096
;mssql.batchsize = 0
;mssql.datetimeconvert = On
mssql.secure_connection = On
mssql.max_procs = 25

Now, I don't know, but could there be something I need to setup in my
Apache 2's httpd.conf ?

Also I have ZoneAlarm allowing TCP on port 80, and 1433.

I would LOVE any help on this anyone can give me, even if it is only a
GOOD guess. I'm willing to try anything at this point.

Cheers;

VanMAn

Jul 17 '05 #3

P: n/a
mj@lightfootarts.com wrote:
Thanks for the reply Jerry. Yes I have readed ALL the user notes, and
every group I can find on this issue. I believe that other people have
had the same problem, and I followed the steps they tool to fix it ...
but still no luck :(

I don't get any kind of error message. For example when I run this
code:

<?php

...

$connt = mssql_connect($host,$user,$password);

if(!$connt)
{
$msg = mssql_get_last_message();
echo $msg;
}

...
?>

$msg if NULL.

Is there any way to tell if my mssql_connect() function is actual going
out to the remote sever and trying to connect? OR if the function is
failing on the local end?

also, these are my MSSQL setting in my php.ini file

mssql.allow_persistent = On
mssql.max_persistent = -1
mssql.max_links = -1
mssql.min_error_severity = 10
mssql.min_message_severity = 10
mssql.compatability_mode = On
;mssql.connect_timeout = 5
;mssql.timeout = 60
;mssql.textlimit = 4096
;mssql.textsize = 4096
;mssql.batchsize = 0
;mssql.datetimeconvert = On
mssql.secure_connection = On
mssql.max_procs = 25

Now, I don't know, but could there be something I need to setup in my
Apache 2's httpd.conf ?

Also I have ZoneAlarm allowing TCP on port 80, and 1433.

I would LOVE any help on this anyone can give me, even if it is only a
GOOD guess. I'm willing to try anything at this point.

Cheers;

VanMAn


VanMAn,

What about your php.log? And what's your error reporting? For
debugging like this you should have error_reporting=E_ALL.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '05 #4

P: n/a
mj
Thanks again Jerry for the reply.

I have my error reporting set to:
error_reporting = E_ALL & ~E_NOTICE


[05-Jun-2005 02:00:11] PHP Warning: mssql_connect() [<a
href='function.mssql-connect'>function.mssql-connect</a>]: Unable to
connect to server: mssql.dumbname.net in
C:\WebServ\wwwroot\htdocs\mssql_send.php on line 12

[05-Jun-2005 02:00:21] PHP Warning: mssql_connect() [<a
href='function.mssql-connect'>function.mssql-connect</a>]: Unable to
connect to server: mssql.dumbname.net in
C:\WebServ\wwwroot\htdocs\mssql_send.php on line 12

[05-Jun-2005 02:03:42] PHP Warning: mssql_connect() [<a
href='function.mssql-connect'>function.mssql-connect</a>]: Unable to
connect to server: mssql.dumbname.net in
C:\WebServ\wwwroot\htdocs\mssql_send.php on line 12

So this what is reported in my php Error.log

Jerry do you know of any way that I can test to see if the
mssql_connect() is making it to the remote server, without have full
access to the remote server? I just what to make sure that the request
is getting there so I can narrow down where my problem is. On my side
or the remote mssql servers side. ( I think my side)

Also if you have any ideas on how I could get around this problem, if I
can't solve it would also be of get value to me. even if I have to
write a CGI script in another language.

Thanks for the help :)

Cheers;

Jul 17 '05 #5

P: n/a
mj
OMG .... ok I think I got it going ... ALMOST :)

I found this:

http://ca3.php.net/function.mssql-connect

and the comment by:
Ilmars Poikans in the top 1/4 of the page.

He said that he had to change his Registry to get it to work

<quote>
I'm working on Windows XP with PHP5 (should work with PHP4 also because
ntwdblib.dll is the same).

My problem was that I needed to connect to remote MS SQL server over
TCP/IP (named pipes weren't an option), but I couldn't, because named
pipes were used all the time.

One of the possible solutions is to install SQL Client Tools and
configure TCP/IP support. I hadn't SQL Server installation disk, so I
found fast solution with registry editing.

I added to registry following entry:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ MSSQLServer\Client\ConnectTo]
(strip space)
"DSQUERY"="DBNETLIB"

It worked! Just specify servername in form "host" or "host,port". I
successfully connected to remote MSSQL7 and MSSQL2000.
</quote>

So I added that value pair, and the next time I can my php code I got
this message:

Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
could not connect to DB

So I think it is working. Now how do I tell it to use SQL Server
Authentication, not Windows Authentication ?

Once I get that working I'm cooking with gas :)

Thanks for the help

Cheers;

VanMan

Jul 17 '05 #6

P: n/a
mj
OMG :)

I got it working, right on !!!

So ... for anyone easy that is have the same problem, I made the follow
registry entry on my local server:

HKEY_LOCAL_MACHINE\SOFTWARE\M*icrosoft\ MSSQLServer\Client\ConnectTo]
DSQUERY=DBNETLIB

and then in my php.ini in the MSSQL area I set:

mssql.secure_connection = Off

AND IT WORK .... YES!!!

Thanks for the Help Jerry.

Cheers;

VanMan

Jul 17 '05 #7

P: n/a
mj@lightfootarts.com wrote:
OMG :)

I got it working, right on !!!

So ... for anyone easy that is have the same problem, I made the follow
registry entry on my local server:

HKEY_LOCAL_MACHINE\SOFTWARE\M*icrosoft\ MSSQLServer\Client\ConnectTo]
DSQUERY=DBNETLIB

and then in my php.ini in the MSSQL area I set:

mssql.secure_connection = Off

AND IT WORK .... YES!!!

Thanks for the Help Jerry.

Cheers;

VanMan


VanMan,

Glad you got it working. But I didn't help much. Just asked a few
questions - you did all the work! :-).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.