2

I'm having heavy issues trying to connect to my MSSQL 2012 Express database, with PHP5 running on an Apache. I have as a test setup just installed a XAMPP with PHP 5.4.4 and Apache running on a Windows 7 machine.

My PHP code (phpmssql_genxml.php):

$connection = mssql_connect('192.168.40.150', $username, $password);
if (!$connection) {  die('Not connected : ' . mssql_get_last_message());} 


$db_selected = mssql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mssql_get_last_message());
} 


$query = "SELECT * FROM Cust WHERE 1";
$result = mssql_query($query);
if (!$result) {  
  die('Invalid query: ' . mssql_get_last_message());
} 

Output when trying to enter the site:

Fatal error: Call to undefined function mssql_connect() in C:\xampp\htdocs\phpmssql_genxml.php on line 13

Even if I try to hardcode the username and password into the string, I still get the same result. Have search a lot on google, but havn't found that post that fixed my issue yet :/ Have enable TCP/IP for the DB instance pipe, even try'd to assign a specific TCP port for it. Have created a rule in the Win7 firewall allowing all traffic to the standard port 1433. Still no luck.

any1 have an idea?? What does the 'Fatal error' part means? Is it the Apache error, PHP or a Database error when trying to connect to it??

6
  • Fatal error is a PHP error. PHP cannot find the function mssql_connect(). Find out (using phpinfo()) where your php.ini file is located. Find the entry extension=php_mssql.dll and uncomment it. Save the file, restart apache and try again. Commented Sep 5, 2012 at 13:49
  • By the way; if you're really using XAMPP, it means that you use MySQL and not MSSQL... Commented Sep 5, 2012 at 13:49
  • 1
    for further informations take a look at php.net/manual/en/mssql.setup.php and the User Contributed Notes on this site. by default XAMPP don't have this function enabled Commented Sep 5, 2012 at 13:55
  • @Lex: I have uncommented the php_mssql.dll but the mssql.dll file doesn't exist in my /php/ext/ folder, think thats may be why its giving fatal error? And yes, I know that MySQL is a part of the XAMPP package, but I have installed a MSSQL 2012 Express server on the same server (its a test server enviroment), because I have another BI system running, that rely on the MSSQL. The MySQL on my test server ain't running. Commented Sep 5, 2012 at 15:04
  • That would be very likely. See if you can download the dll from somewhere (try googling "php_mssql.dll windows php [your phpversion]") Commented Sep 5, 2012 at 15:05

2 Answers 2

2

You are missing MSSQL driver from your PHP setup. Download it from here, assuming you have the required system configuration mentioned on the page.

Setting up, from their instructions:

  1. Download SQLSRV30.EXE to a temporary directory
  2. Run SQLSRV30.EXE
  3. When prompted, enter the path to the PHP extensions directory
  4. After extracting the files, read the Installation section of the SQLSRV30_Readme.htm file for next steps

I would also recommend using standard Apache + PHP installation, if you plan to work with MSSQL, instead of any *AMP package.

Sign up to request clarification or add additional context in comments.

4 Comments

Since the requirements is: A supported operating system, such as: Windows Server 2003 Service Pack 1 Windows XP Service Pack 3 Windows Vista Service Pack 1 or later Windows Server 2008 Windows Server 2008 R2 Windows 7 I guess it doesn't matter if its apache or IIS, since it have to be running on a windows machine? Or am I wrong? When deployed my target was a Linux machine running Apache for the webpart, with MSSQL support (linking to my Windows XP machine running MSSQL Express). But if the driver for the support NEED a win box, then that setup is more or less 'destroyed'.
Right, the requirement is web server running PHP, be it IIS or Apache. So if I get it right, you're developing on win machine but your target is actually Linux machine? yes, definitely there are different steps to install drivers in each system. If you need to develop on a windows machine, I'd recommend running Linux on a virtual machine, since PHP in general has a lot operating system differences. My personal experience is that the same PHP code often does not work on different OSs or works in a different way - although this somewhat depends on what is being done.
Well, let me explain the setup a bit. There is a MSSQL08 Express server running on a Windows machine, that is deployed and running BI. I'm playing around with implementing some Google Maps into the app already running, which is why I'm using PHP right now. Instead of setting up a new Windows machine running IIS with PHP support, my target server is planned to be a Linux machine with Apache PHP, but in both cases I need the support of making connections from the Webserv to the MSSQL08 db. The only reason the windows machine is into consideration is for test purpose only. What would you suggest?
I'd suggest using some more cross-platform database, such as MySQL or PostgreSQL. :) If you need to use MSSQL connecting from Linux env, there are some instructions for example here. I have no experience with that though.
1

You don't need to use SQLSRV30 as this was not the solution that I needed though some may find it useful. I have a local dev environment running XAMPP + php5.5.9 + MSSQL2012 and I needed to use mssql functions because thats what we use at work on our servers. So I use freetds and "luckily" found this:

https://moodle.org/mod/forum/discuss.php?d=232844

where one of the users already compiled the php_dblib.dll TS and NTS for my php version suffice to say I have everything working and using all the MSSQL functions that our dev team is used to. The extension for mssql support can always be compiled.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.