Connection info on production and development server

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
alex
User
Posts: 267

Connection info on production and development server

Post by alex »

Hello!

In earlier versions of phpmaker I used Database_Connecting event:

if (CurrentUserIP() != "127.0.0.1") {
	$info["host"] = "localhost";
	$info["user"] = "xxx";
	$info["pass"] = "xxx";
	$info["db"] = "xxx";
}

It doesn't work in phpmaker in v2024. So now moving files from localhost to server I always need to change manually "ENVIRONMENT" => "development" to "production" in config.php

Please advise how to solve.


alex
User
Posts: 267

Post by alex »

I have tried to use example from Database_Connecting:

function Database_Connecting(&$info) {
    //var_dump($info);
    // Assume the scripts are generated with connection info for local database
    if (!IsLocal()) { // Not local (Production)
        $info["host"] = "localhost";
        $info["user"] = "production_user";
        $info["password"] = "production_pwd";
        $info["dbname"] = "production_db";
    }
}

Advanced Settings > ENVIRONMENT set as "development"

var_dump($info) on production server displays right data.

I did regenerate all project and Composer Update.

Despite I still get error:

/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php(101): An exception occurred in the driver: Access denied for user 'production_db'@'localhost' (using password: YES)

if I use above Database_Connecting settings and manually change "ENVIRONMENT" => "development" to "production" in config.php then I get error: An internal error has occurred while processing your request.

Please help.


arbei
User
Posts: 9384

Post by arbei »

alex wrote:

$info["user"] = "production_user";
/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php(101): An exception occurred in the driver: Access denied for user 'production_db'@'localhost' (using password: YES)

You either have typo or you did not post correct code for the user name. Either way, the error message tells that the connection info is incorrect, the user "production_db" at "localhost" on your production server does not have permissions to access the database.

Note that if the MySQL server is not on the same server as the web server, you can't use "localhost", you need to specify the IP of the MySQL server. You also need to configure your MySQL server to allow connection from your web server (localhost or IP) or you get "Access denied".

Note that the "ENVIRONMENT" config setting is irrelevant because you use Database_Connecting server event, which has overriden the development/production connection info generated in the config.develoment.php/config.production.php.

Whenever you see internal server errors, turn on Debug to check the actual error.


alex
User
Posts: 267

Post by alex »

I figured out that I did mistake. My mysql db has different port on production server and I forgot about that. My problem was solved after I changed Database_Connecting setting to:

$info["host"] = "localhost:3310";

My fault sorry and thank you!


Post Reply