do anyone knows how to connect to a MS SQL server(database in internet,i have ip,db username and db password).i used mssql_connect from my PHP ,but how to activate it in windows or Ubutu.i download all dll files needed but i cant connect..pls help me....

Dani AI

Generated

Short, practical checklist and a modern path forward for PHP-to-MSSQL connections (builds on and comments).

The old mssql extension (and the ntwdblib.dll hacks) sometimes work for legacy setups but are fragile and unsupported in current PHP. Prefer the supported drivers: on Windows use Microsoft's sqlsrv / PDO_SQLSRV; on Linux/Ubuntu use either FreeTDS with PDO_DBLIB or the Microsoft ODBC driver + sqlsrv/pdo_sqlsrv. See Microsoft and FreeTDS docs for downloads and install notes: Microsoft Drivers for PHP for SQL Server and FreeTDS. The PHP mssql extension is deprecated/removed in newer PHP releases (see PHP manual).

Quick installation/troubleshoot checklist

  • Match driver binary to PHP build: PHP version, architecture (x86 vs x64) and thread-safety (TS vs NTS). Also install the required Visual C++ runtime on Windows.
  • Verify SQL Server accepts remote TCP connections (TCP/IP enabled, correct port or instance name, SQL Browser for named instances) and that firewall rules allow the port (default 1433).
  • Confirm authentication mode: SQL Server must allow SQL logins for username/password connection (Mixed Mode).
  • Test network reachability with a native client (sqlcmd/isql) or by connecting with an ODBC client before debugging PHP.
  • Capture errors: enable PHP error logging and check SQL Server error logs; driver error arrays give actionable messages.

Example using the Microsoft driver (different from the mssql_* API shown earlier):

$server = "1.2.3.4,1433"; // or "server\INSTANCE"
$conn = sqlsrv_connect($server, ["UID"=>"user","PWD"=>"pass","Database"=>"db"]);
if (!$conn) { die(print_r(sqlsrv_errors(), true)); }

If the connection still fails, record the exact driver error text and whether the native client can connect; those details usually identify whether the problem is network, authentication, port/instance, or a driver/PHP mismatch.

Recommended Answers

All 2 Replies

How do you mean in Windows? It will be better understood if you will expantiaite on "activate it in windows or Ubutu". Do you want to connect to your database from your windows operating system such that you will be able to export/import data?
If yes, let the forum know.
Thank you.

Have you checked that you have the latest ntwdblib.dll( this has solved my connection problem)? You should paste this dll over your dll's from apache and php(I think it can be found in two places). Restart apache
then use mssql_connect like this:

$myServer = "xx.xx.xx.xx";
$myUser = "sa";
$myPass = "yyyyyyyyyyyyy";
$myDB = "zzzzzzzzzzz";

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer");

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB");

If it still does not work you should try to connect to the database through MS SQL Management Studio.
If it does not connect talk to the owner of the database

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.