grmihel
grmihel

Reputation: 846

mssql_connect() with PHP5 and MSSQL2012 Express

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??

Upvotes: 2

Views: 48768

Answers (2)

greaterKing
greaterKing

Reputation: 317

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.

Upvotes: 1

eis
eis

Reputation: 53482

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.

Upvotes: 2

Related Questions