Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1812
  • Last Modified:

MSSQL with Apache and PHP on Linux

I can use freetds and php to connect to mssql servers from the command line for example the following returns exactly what is expected:
[root@INTRA1 html]# cat testsql1.php
$hostname = "database";
$username = "sa";
$password = "";
$dbName = "mydatabase";

MSSQL_CONNECT($hostname,$username,$password) or DIE("DATABASE FAILED TO RESPOND.");
mssql_select_db($dbName) or DIE("Table unavailable");

$query = "SELECT * FROM dbo.cdp";

$result = mssql_query( $query );

for ($i = 0; $i < mssql_num_rows( $result ); ++$i)
         $line = mssql_fetch_row($result);
         print( "$line[0] - $line[1] - $line[2] - $line[3] - $line[4]\n");

BUT trying to run the same code through a browser Apache returns the follwing:
Fatal error: Call to undefined function: mssql_connect() in /var/www/html/testsql1.php on line 7
Any help would be appreciated.
  • 2
3 Solutions
Are you sure the MSSQL PHP lib is installed?

Undefined function usually means the given function has not been found, so it must be that the lib is not installed.

You should check phpinfo() to make sure it is installed. If not, you can recompile with MSSQL as detailed in the manual:
Also, just noticed this:
$hostname = "database";

Is that a valid hostname?
You need to have the MSSQL library installed, indeed.

To get the MSSQL functions to work, you have to compile PHP with --with-mssql,
and FreeTDS should be compiled using --enable-msdblib.

You can check your PHP configuration with the command phpinfo().

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now