0

I am relatively new to both PHP and SQL and I am in the process of developing a PHP application to run on a work server. I have created a test page using code from php.net to literally test the connection and I keep getting the following error:

Fatal error: Call to undefined function mssql_connect()

My code is

<?php
$server = 'myserver\SQLEXPRESS';

$link = mssql_connect($server, 'username', 'password');

if (!$link) {  
die('Something went wrong while connecting to MSSQL');  
}  
?>

Obviously I cant proceed with the project until I can establish the connection, is there anything I could be missing or doing wrong?

Any help will be very much appreciated!

BAdmin
  • 927
  • 1
  • 11
  • 19
user3361017
  • 61
  • 2
  • 11

3 Answers3

0

There can be number of reasons. Most probably is that you use PHP 5.3+ and mssql functions are not supported since this version. You should use PDO or SQLSRV driver from Microsoft. Try to run phpinfo() to see which drivers are supported on your installation.

jpesout
  • 688
  • 5
  • 12
0

i have forgotten from where i got this answer, but it has been more than 1 year.

1. First search for `;extension=php_mssql.dll` in php.ini file and remove semicolon `;`.
2. Copy `ntwdblib.dll` from php directory to windows root directory, sometimes it dosen't
work so you will have to copy it in system32 directory.
3. Copy `php_mssql.dll` from php directory to windows root directory, again sometimes it 
dosen't work so you will have to copy it in system32 directory.
4. Search or download `msvcr71.dll` and copy it in windows system32 directory.
5. Restart apache web server.

This works for me. Please try and let me know the result.

vgijre
  • 1
  • 2
  • Just another question which I maybe should have asked initially. I am using PHPmyadmin to host the PHP site, but the server that has the sql server on is a different server, which one needs the php extensions etc? – user3361017 Mar 20 '14 at 08:43
  • I don't know for sure but the one on which the web server is installed. If necessary you can copy files on both servers. – vgijre Mar 20 '14 at 08:54
  • which php.ini file? there are two within the easyphp folder one in binaries\conf files and one in php\php_runningversion. I cannot locate `;extension=php_mssql.dll on either. Thanks for the help – user3361017 Mar 21 '14 at 11:15
  • use `phpinfo()` function of php to view configuration of php. Search for string "_Configuration File (php.ini) Path_" or "_Loaded Configuration File_". This will show you the location of _php.ini_ file, if you cannot loacate `;extension=php_mssql.dll` then just add the line `extension=php_mssql.dll` with other extensions. And restart the web server after making changes. – vgijre Mar 22 '14 at 04:28
0

Just an update, after looking at other threads on this site I have found a solution! The answer to the following question solved it for me:

Trying to install MSSQL drivers with EasyPHP 12

Thank you all very much for your help and thank you to the person responsible for the original answer!

Community
  • 1
  • 1
user3361017
  • 61
  • 2
  • 11