Chris1394 Posted May 14, 2008 Share Posted May 14, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/105539-fatal-error-call-to-undefined-function-mssql_connect/ Share on other sites More sharing options...
gnawz Posted May 14, 2008 Share Posted May 14, 2008 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/105539-fatal-error-call-to-undefined-function-mssql_connect/#findComment-540715 Share on other sites More sharing options...
PFMaBiSmAd Posted May 14, 2008 Share Posted May 14, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/105539-fatal-error-call-to-undefined-function-mssql_connect/#findComment-540860 Share on other sites More sharing options...
Chris1394 Posted May 14, 2008 Author Share Posted May 14, 2008 Thank you for the advice, I will be working on this again tonight, and I'll add any additional info then. Quote Link to comment https://forums.phpfreaks.com/topic/105539-fatal-error-call-to-undefined-function-mssql_connect/#findComment-540903 Share on other sites More sharing options...
Chris1394 Posted May 16, 2008 Author Share Posted May 16, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/105539-fatal-error-call-to-undefined-function-mssql_connect/#findComment-542558 Share on other sites More sharing options...
PFMaBiSmAd Posted May 16, 2008 Share Posted May 16, 2008 How about the first one - The php.ini that you are changing must be the one that php is using. Quote Link to comment https://forums.phpfreaks.com/topic/105539-fatal-error-call-to-undefined-function-mssql_connect/#findComment-542566 Share on other sites More sharing options...
Chris1394 Posted May 16, 2008 Author Share Posted May 16, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/105539-fatal-error-call-to-undefined-function-mssql_connect/#findComment-542900 Share on other sites More sharing options...
PFMaBiSmAd Posted May 16, 2008 Share Posted May 16, 2008 Here is a nearly identical thread - http://www.phpfreaks.com/forums/index.php/topic,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. Quote Link to comment https://forums.phpfreaks.com/topic/105539-fatal-error-call-to-undefined-function-mssql_connect/#findComment-542921 Share on other sites More sharing options...
Chris1394 Posted May 17, 2008 Author Share Posted May 17, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/105539-fatal-error-call-to-undefined-function-mssql_connect/#findComment-543355 Share on other sites More sharing options...
Chris1394 Posted May 17, 2008 Author Share Posted May 17, 2008 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.* Quote Link to comment https://forums.phpfreaks.com/topic/105539-fatal-error-call-to-undefined-function-mssql_connect/#findComment-543574 Share on other sites More sharing options...
Chris1394 Posted May 17, 2008 Author Share Posted May 17, 2008 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/105539-fatal-error-call-to-undefined-function-mssql_connect/#findComment-543632 Share on other sites More sharing options...
tripleM Posted August 17, 2009 Share Posted August 17, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/105539-fatal-error-call-to-undefined-function-mssql_connect/#findComment-899938 Share on other sites More sharing options...
michaelmuller Posted September 3, 2009 Share Posted September 3, 2009 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..." Quote Link to comment https://forums.phpfreaks.com/topic/105539-fatal-error-call-to-undefined-function-mssql_connect/#findComment-911806 Share on other sites More sharing options...
foliady Posted October 7, 2009 Share Posted October 7, 2009 Thank you for the advice Quote Link to comment https://forums.phpfreaks.com/topic/105539-fatal-error-call-to-undefined-function-mssql_connect/#findComment-932657 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.