Droffo Posted September 7, 2014 Share Posted September 7, 2014 Before reading, just know I am NOT a PHP programmer and have no experience with PHP. I am just trying to install a premade php based website. My questions is: How do I make .php pages connect to my database? I know the question is very broad and probably doesn't really make sense but I've been having errors trying to install/configure a php website. The php website has a config which I have filled out correctly and seems to work on my PC via localhost using XAMPP fine but it doesn't work on my Windows Server 2012 Apache machine whenever the .php configuration tries to alter or conenct to the MySQL database it displays errors like this: Fatal error: Call to undefined function mysql_connect() in C:\Apache24\htdocs\includes\classes.php on line 378 That's just an example of one predefined PHP website errors that I've received they are all very similar. What I think is happening is the PHP code is trying to connect to the database but there's some sort of configuration variable on Apache that I have not correctly filled out. I have tried this twice with two different CMS and searched google far and wide to find an answer to my problem. I hope the answer is something simple. If you need anything because you think you know what is happening then I will provide any information needed to fix this problem. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/290900-windows-server-2012-question/ Share on other sites More sharing options...
requinix Posted September 7, 2014 Share Posted September 7, 2014 Not sure how you managed to avoid the solution when searching for "call to undefined function mysql_connect". You don't have the mysql extension installed with PHP. (Not Apache.) Check your php.ini for a line that looks like ;extension = php_mysql.dllremove the semicolon, and restart Apache. Then try again. Quote Link to comment https://forums.phpfreaks.com/topic/290900-windows-server-2012-question/#findComment-1490230 Share on other sites More sharing options...
Ch0cu3r Posted September 7, 2014 Share Posted September 7, 2014 @Droffo as you have recently install Apache and PHP you need to configure PHP for what extensions to use. The MySQL functions are only available when the you have enabled the mysql extension ( as requinix suggested) above. Before enabling any extensions I recommend that you add your PHP installation folder to the Windows PATH system variable. Then open the php.ini and configure the extension_dir directive to point to your PHP installation extension folder. Only then you can start enabling extensions. Quote Link to comment https://forums.phpfreaks.com/topic/290900-windows-server-2012-question/#findComment-1490231 Share on other sites More sharing options...
Droffo Posted September 7, 2014 Author Share Posted September 7, 2014 Not sure how you managed to avoid the solution when searching for "call to undefined function mysql_connect". You don't have the mysql extension installed with PHP. (Not Apache.) Check your php.ini for a line that looks like ;extension = php_mysql.dllremove the semicolon, and restart Apache. Then try again. @Droffo as you have recently install Apache and PHP you need to configure PHP for what extensions to use. The MySQL functions are only available when the you have enabled the mysql extension ( as requinix suggested) above. Before enabling any extensions I recommend that you add your PHP installation folder to the Windows PATH system variable. Then open the php.ini and configure the extension_dir directive to point to your PHP installation extension folder. Only then you can start enabling extensions. Thank you very much to both of you. You are awesome and I wish I could best answer you both! Quote Link to comment https://forums.phpfreaks.com/topic/290900-windows-server-2012-question/#findComment-1490234 Share on other sites More sharing options...
Droffo Posted September 7, 2014 Author Share Posted September 7, 2014 (edited) Not sure how you managed to avoid the solution when searching for "call to undefined function mysql_connect". You don't have the mysql extension installed with PHP. (Not Apache.) Check your php.ini for a line that looks like;extension = php_mysql.dllremove the semicolon, and restart Apache. Then try again. @Droffo as you have recently install Apache and PHP you need to configure PHP for what extensions to use. The MySQL functions are only available when the you have enabled the mysql extension ( as requinix suggested) above. Before enabling any extensions I recommend that you add your PHP installation folder to the Windows PATH system variable. Then open the php.ini and configure the extension_dir directive to point to your PHP installation extension folder. Only then you can start enabling extensions. Thank you very much to both of you for replying. I have set a new PATH by going into Environment Variables and adding ";C:\php" and have also edited the php.ini to resemble this: ;extension=php_bz2.dll ;extension=php_curl.dll ;extension=php_fileinfo.dll ;extension=php_gd2.dll ;extension=php_gettext.dll ;extension=php_gmp.dll ;extension=php_intl.dll ;extension=php_imap.dll ;extension=php_interbase.dll ;extension=php_ldap.dll ;extension=php_mbstring.dll ;extension=php_exif.dll ; Must be after mbstring as it depends on it extension=php_mysql.dll ;extension=php_mysqli.dll ;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client ;extension=php_openssl.dll ;extension=php_pdo_firebird.dll extension=php_pdo_mysql.dll ;extension=php_pdo_oci.dll ;extension=php_pdo_odbc.dll ;extension=php_pdo_pgsql.dll ;extension=php_pdo_sqlite.dll ;extension=php_pgsql.dll ;extension=php_pspell.dll ;extension=php_shmop.dll I am still getting this error. Here is the script PHP is attempting to execute with MySQL (perhaps you could help me at working out which extension I need): class PoopDatabase { var $connection; var $error; var $lastquery; function PoopDatabase($conn){ switch($conn['server']){ case "mysql": $this->connection = mysql_connect($conn['host'].":".$conn['port'], $conn['username'], $conn['password'], true); Fatal error: Call to undefined function mysql_connect() in C:\Apache24\htdocs\includes\classes.php on line 378 This is the error line: $this->connection = mysql_connect($conn['host'].":".$conn['port'], $conn['username'], $conn['password'], true); Edited September 7, 2014 by Droffo Quote Link to comment https://forums.phpfreaks.com/topic/290900-windows-server-2012-question/#findComment-1490235 Share on other sites More sharing options...
Solution Ch0cu3r Posted September 7, 2014 Solution Share Posted September 7, 2014 Make sure you have set the extension_dir directive to C:\php\ext and have restarted Apache too. Quote Link to comment https://forums.phpfreaks.com/topic/290900-windows-server-2012-question/#findComment-1490236 Share on other sites More sharing options...
Droffo Posted September 7, 2014 Author Share Posted September 7, 2014 (edited) Make sure you have set the extension_dir directive to C:\php\ext and have restarted Apache too. I now get this error: Deprecated : mysql_connect (): The mysql extension is deprecated and removed Will Be in the future: use mysqli or PDO INSTEAD in C: \ Apache24 \ htdocs \ install \ ajax-3 \ mysql.php on line 3 true Edited September 7, 2014 by Droffo Quote Link to comment https://forums.phpfreaks.com/topic/290900-windows-server-2012-question/#findComment-1490237 Share on other sites More sharing options...
Droffo Posted September 7, 2014 Author Share Posted September 7, 2014 Here is line 3: mysql_connect($_POST['dbhost'],$_POST['uname'],$_POST['pwd']) or die('Les informations de connexion vers la base de donnée sont incorrecte.'); Quote Link to comment https://forums.phpfreaks.com/topic/290900-windows-server-2012-question/#findComment-1490238 Share on other sites More sharing options...
Ch0cu3r Posted September 7, 2014 Share Posted September 7, 2014 (edited) Yep mysql extension is now enabled! But you will get that Deprecated message because the mysql_* functions are no longer supported, meaning they could be removed in future versions of PHP. It is recommend to convert your code over to PDO or MySQLi. You can lower error_reporting to not report deprecated warnings. By setting it to something like error_reporting = E_ALL & ~E_DEPRECATED But you should take action in resolving the deprecated warnings and not just ignoring them. Edited September 7, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/290900-windows-server-2012-question/#findComment-1490240 Share on other sites More sharing options...
Droffo Posted September 7, 2014 Author Share Posted September 7, 2014 (edited) Yep mysql extension is now enabled! But you will get that Deprecated message because the mysql_* functions are no longer supported, meaning they could be removed in future versions of PHP. It is recommend to convert your code over to PDO or MySQLi. You can lower error_reporting to not report deprecated warnings. By setting it to something like error_reporting = E_ALL & ~E_DEPRECATED But you should take action in resolving the deprecated warnings and not just ignoring them. Thanks, I attempted to enter the code on the second line and ended up with a parse error: Parse error: syntax error, unexpected '=' in C:\Apache24\htdocs\install\index.php on line 2 Edited September 7, 2014 by Droffo Quote Link to comment https://forums.phpfreaks.com/topic/290900-windows-server-2012-question/#findComment-1490253 Share on other sites More sharing options...
Ch0cu3r Posted September 7, 2014 Share Posted September 7, 2014 I have not posted code. error_reporting is a directive in the php.ini for setting the error reporting level. If you want to modify the error reporting level (temporarily) within your script you can use error_reporting(E_ALL & ~E_DEPRECATED); Quote Link to comment https://forums.phpfreaks.com/topic/290900-windows-server-2012-question/#findComment-1490255 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.