Jump to content

Windows Server 2012 Question


Go to solution Solved by Ch0cu3r,

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/290900-windows-server-2012-question/
Share on other sites

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.dll
remove 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.

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.dll
remove 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!  :tease-03:

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 by Droffo

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 by Droffo

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 by Ch0cu3r

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 by Droffo

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);
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.