Jump to content


Photo

Fatal error: Call to undefined function mssql_connect()


  • Please log in to reply
13 replies to this topic

#1 Chris1394

Chris1394

    Newbie

  • New Members
  • Pip
  • 7 posts

Posted 13 May 2008 - 11:28 PM

Hi all,

I'm running Windows Server 2003, MS Sql 2005, and IIS6.  I am trying to connect php to my sql database, and I keep getting the following error from the script below:

Fatal error: Call to undefined function mssql_connect() in C:\Inetpub\wwwroot\testphpsql.php on line 4

<html>
<body>
<?php
$con = mssql_connect ("servername", "user", "password");
mssql_select_db ("ad-ls_phpbb", $con);
$sql= "SELECT * FROM TestTable";
$rs= mssql_query ($sql, $con);
echo "The field number one is: ";
echo mssql_result ($rs, 0, 0);
mssql_close ($con);
?>
</body>
</html>


I'm new to PHP in general, but I have copied all of my .dlls from my php folder into my system32 folder, and I have uncommented extension=php_mssql.dll in my php.ini file. 

I'm lost, I've looked though the boards and used search but nobody ever seems to come back and say what fixed this issue.  I'll be greatful for any help.

Thanks,
Chris

#2 gnawz

gnawz

    Advanced Member

  • Members
  • PipPipPip
  • 237 posts

Posted 14 May 2008 - 03:12 AM

Remove $con from this line
<?
$rs= mssql_query ($sql, $con);
//to become
$rs= mssql_query ($sql);
or connect as follows:
//db connection
$con = mssql_connect ($dbHost, $dbUser, $dbPass) or die ('MsSQL connect failed. ' . mssql_error());
mssql_select_db($dbName) or die('Cannot select database. ' . mssql_error());

$dbHost = 'localhost';
$dbUser = 'root';
$dbPass = '';
$dbName = '';

//define your parameters accordingly
?>

#3 PFMaBiSmAd

PFMaBiSmAd

    Advanced Member

  • Staff Alumni
  • 16,767 posts
  • LocationColorado, U.S.A.

Posted 14 May 2008 - 07:35 AM

For the mssql extension to work, all of the following must be true -

The php.ini that you are changing must be the one that php is using.

The php_mssql.dll must be in the ext folder.

The extension_dir setting in php.ini must be set to the ext folder, something like  extension_dir = c:\php\ext

To get changes made to php.ini to take effect, you must stop and start the IIS web service. Do this in the services control panel or reboot your computer. Just stopping and starting the web site in the IIS management console is not enough.

mssql requires: ntwdblib.dll to be available on the Windows PATH. It is better to add the php folder to the Windows PATH instead of moving any files around. Re-logon or reboot your computer to get any changes made to the Windows PATH statement to take effect.

The php folder must have proper permissions set to allow the IIS user account to read the files in the php folder and in the ext folder.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

#4 Chris1394

Chris1394

    Newbie

  • New Members
  • Pip
  • 7 posts

Posted 14 May 2008 - 09:06 AM

Thank you for the advice, I will be working on this again tonight, and I'll add any additional info then.

#5 Chris1394

Chris1394

    Newbie

  • New Members
  • Pip
  • 7 posts

Posted 15 May 2008 - 10:31 PM

Still banging my head on the desk oh this one. 

PFMaBiSmAd,  I have made sure that each file that comes up in *php*.ini and looks like like a php.ini file has php_mssql.dll uncommented. 

php_mssql.dll is in the folder that is specified by extension_dr in each .ini

I have stopped and restarted IIS several times, used iisreset/stop and /start and have rebooted the computer.

mtwdblib.dll is in system32, AND the php dir is in the PATH variable.

I reset permissions on the php folder to full control for everyone.  Might not be the smartest thing, but I wanted to make sure it wasn't a permissions error since my server is not yet live.


Gnawz,

<html>
<body>
<?
$rs= mssql_query ($sql);
//or connect as follows:
//db connection
$con = mssql_connect ($dbHost, $dbUser, $dbPass) or die ('MsSQL connect failed. ' . mssql_error());
mssql_select_db($dbName) or die('Cannot select database. ' . mssql_error());

  $dbHost = 'localhost';
  $dbUser = '######';
  $dbPass = '######';
  $dbName = '######';

//define your parameters accordingly
?>
</body>
</html>

Still gives me:
Fatal error: Call to undefined function mssql_query() in C:\Inetpub\wwwroot\testphpsql.php on line 4

I of course did define username, password, and db

Thank you

#6 PFMaBiSmAd

PFMaBiSmAd

    Advanced Member

  • Staff Alumni
  • 16,767 posts
  • LocationColorado, U.S.A.

Posted 15 May 2008 - 10:39 PM

How about the first one -

The php.ini that you are changing must be the one that php is using.


Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

#7 Chris1394

Chris1394

    Newbie

  • New Members
  • Pip
  • 7 posts

Posted 16 May 2008 - 09:52 AM

4 php.ini files come up in my system with a search for *php*.ini.    Two called php.ini, one called php5.ini, and one called php4.ini.   How do I tell which one is being used.  The folder I added to PATH contains php5.ini

I made sure all four had php_mssql.dll without the leading ';'.

I made sure all four pointed to the folder with php_mssql.dll in the  extension_dir variable.


Like I stated earlier, I'm a complete newb at this.  I have 0 experence with php but was forced to take on a project that needs it.
Thanks for your help.


#8 PFMaBiSmAd

PFMaBiSmAd

    Advanced Member

  • Staff Alumni
  • 16,767 posts
  • LocationColorado, U.S.A.

Posted 16 May 2008 - 10:28 AM

Here is a nearly identical thread - http://www.phpfreaks...c,197174.0.html

Check wildteen88's instructions in that thread to use a phpinfo(); statement to see what if any php.ini is getting loaded.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

#9 Chris1394

Chris1394

    Newbie

  • New Members
  • Pip
  • 7 posts

Posted 16 May 2008 - 10:18 PM

I've read the other topic mentioned, and I have added my PHP folder where php.ini resides to PATH, and rebooted several times, but it still insists on looking in c:\windows for the php.ini file when I check phpinfo.

Here is my path var.

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\XAMPP\php\;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\


Why won't it look to my php folder?  Looking in my C:\windows folder, there is no php.ini there.  How is even phpinfo even working if it is looking for a place where the ini doesn't live?

#10 Chris1394

Chris1394

    Newbie

  • New Members
  • Pip
  • 7 posts

Posted 17 May 2008 - 10:48 AM

Ok, even more confusing.  This is cut/paste from phpinfo

System  Windows NT 5.2 build 3790 
Build Date  Nov 8 2007 23:18:08 
Configure Command  cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared" 
Server API  ISAPI 
Virtual Directory Support  enabled 
Configuration File (php.ini) Path  C:\WINDOWS    ???
Loaded Configuration File  C:\XAMPP\php\php.ini 
  ???
PHP API  20041225 
PHP Extension  20060613 
Zend Extension  220060519 
Debug Build  no 
Thread Safety  enabled 
Zend Memory Manager  enabled 
IPv6 Support  enabled 
Registered PHP Streams  php, file, data, http, ftp, compress.zlib, zip 
Registered Stream Socket Transports  tcp, udp 
Registered Stream Filters  convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, zlib.*


#11 Chris1394

Chris1394

    Newbie

  • New Members
  • Pip
  • 7 posts

Posted 17 May 2008 - 11:37 AM

<?php

if (function_exists('mssql_fetch_row')) {
echo "MSSQL functions are available.<br />\n";
} else {
echo "MSSQL functions are not available.<br />\n";
}

?>

Returns: MSSQL functions are available

#12 tripleM

tripleM

    Member

  • Members
  • PipPip
  • 28 posts

Posted 17 August 2009 - 05:45 AM

Hi all,

I'm running Windows XP, MS Sql 2005, and APACHE2.0.x.  I am trying to connect php to my sql database, and I keep getting the following error from the script below:

Fatal error: Call to undefined function mssql_connect() in Fatal error:
Call to undefined function mssql_connect()

MSSQL functions not available. What should i do , to available and execute it succesfully?

Thanks,
TripleM

#13 michaelmuller

michaelmuller

    Newbie

  • New Members
  • Pip
  • 5 posts

Posted 03 September 2009 - 12:27 PM

I was having the same problem. Rather than force Windows to load php.ini from the c:\php folder I just copied it to the c:\windows folder (as it apparently wanted to) and all was right with the world.

BTW, if you're seeing TWO copies of php.ini in the same folder, then something is dramatically wrong, because no OS that I know of will allow two files with the same filename to exist in the same folder.  My guess is you have Windows "hiding known file extensions" and you're really looking at php.ini.txt and php.ini.???

When in Explorer. you should go to Tools > Folder Options > View... and UNCHECK "Hide extensions..."

#14 foliady

foliady

    Newbie

  • New Members
  • Pip
  • 6 posts

Posted 07 October 2009 - 04:15 PM

Thank you for the advice




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com