Re: Question on Connecting to Microsoft SQL Server from PHP
| From: | Dan Shirah | Date: | Tue, 12 Jun 2007 18:34:02 +0000 |
| Subject: | Re: Question on Connecting to Microsoft SQL Server from PHP | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-256744@lists.php.net to get a copy of this message | ||
In my PHP page I have the following:
$sql = mssql_connect ("xx.xx.xx.xx:xxxx", "xx", "xxxxxx");
$conn=mssql_select_db("xx", $sql);
Since both servers are within your local network, you should be able to
connect as follows:
$connection = mssql_connect('SERVERNAME','username','password') or die
('Cannot connect to server');
$database = mssql_select_db("my_database_name", $mssql_connection) or die
('DB selection failed');
Possible SQL Server issues:
Unless your internal network does not trust your other servers, you
should not have to use ip:port. Just use the servers actual name.
I would also put in the "or die" statements so you know if you are failing
connecting to the server or to the DB.
Also, make sure the username/password you are using to connect is setup in
MSSQL Server as a valid user for your database.
Possible PHP issues:
In your php.ini file make sure that extension=php_mssql.dll is uncommented
You should only have mssql.secure_connection = Off set to On if you are
trying to use NT Authentification.
On 6/12/07, Edward Kay <edward@labhut.com> wrote:
All: I can't seem to connect to a SQL Server database with PHP. I have read the php.net documentation and so many other forums on the Internet that my eyes were literally blood shot. Today I thought I would try this route. I have PHP and Apache installed on my local machine. They work fine as I created another application with them (and MySQL) that worked as expected/designed. I want to connect to MS SQL Server 2000 that rests on another machine here at work. I can reach the tables and do whatever I want with them from my machine through SQL Query Analyzer. (The other machine runs a Windows Server. So I am trying to connect from one Windows box to another Windows box.) So I know that I can connect to the tables (and the machine that they rest on) from my machine. It is just that I get the following error when I load my PHP page: "Warning: mssql_connect() [[ http://localhost/development_files/ordertrackno/where_is_it.php/fu nction.mssql-connect ]function.mssql-connect]: Unable to connect to server: . . . " In my PHP page I have the following: $sql = mssql_connect ("xx.xx.xx.xx:xxxx", "xx", "xxxxxx"); $conn=mssql_select_db("xx", $sql); etc I have tried replacing the semicolon with a comma as some have said. I get the same error. I have tried replacing the quotation marks with an apostrophe and I get the same error. I have the Client tools installed on my machine. (I should mention that they are not installed on the Apache on my machine as I could not get them to install from the SQL Server disk to that location--only to the hardrive.). Again, they connect to the database. I can query the database from my machine. I have the latest ntwdblib.dllinstalled in the php, php\extension, apache\bin, and system 32 directories. What else . . . I have tried setting the msssql.secure_connection to both off and on and I still get the same error. I have ensured that TCP/IP and Named Pipes are enabled in the SQL Configuration tool. I have asked the network guy to help out but no luck there. Again, I am at a loss and need to get this up and running. Any suggestions would be appreciated. Thanks. Tommy Do you have any firewall software running on your local PC? (e.g. ZoneAlarm) This could be blocking the connection from Apache but allowing it for your other SQL client tools... Edward -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php