Jump to content

Archived

This topic is now archived and is closed to further replies.

Chris1394

Fatal error: Call to undefined function mssql_connect()

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

?>

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

How about the first one -

 

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

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.*

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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..."

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.