Creating Production and Test projects

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

Creating Production and Test projects

Post by daveb »

I would like to run two similar environments with separate databases, code and pmp files. Firstly I will create a test setup. When that is working and "approved" I would like to copy it to production using a different database. I can easily create the second database and the htdocs folder for the code. However, when I copy the pmp file and then attempt to update the database connection, it warns that all the customization will be lost! How can I make the copy without losing these settings, but accessing a new database. In most cases the test system will be on an XAMPP server and the production system on a remote server, but there could be both copies running on the same XAMPP server or the same remote server.


mobhar
User
Posts: 11735

Post by mobhar »

You may simply use Database_Connecting server event to define your database both for localhost and for your production server.

In other words, you don't have to change your database settings anymore if you use that server event. You may define both settings in that event. This helps me a lot after re-generating ALL the script files and upload it to my production server.


daveb
User
Posts: 32

Post by daveb »

Thanks for the note. I copied my pmp file and added this code in the new file:

// Database Connecting event
function Database_Connecting(&$info)
    $info["dbname"] = "newname_2024";
}

I also changed the project folder to a new location within the htdocs folder, but still on my XAMPP test server, and regenerated the whole project. Vardump ($info) shows the dbname has been changed but both versions of my project are updating the same (original) database. I did not change the host, password, user or port as the new database is in the same folder. I created the new database by copying the old database folder to create a new folder in the mysql folder and it appears to be correct using phpadmin.

Have I missed something?

Dave


mobhar
User
Posts: 11735

Post by mobhar »

You should always refer to the Example in that server event, for example:

function Database_Connecting(&$info) {
    //var_dump($info);
    // Assume the scripts are generated with connection info for local database
    if (!IsLocal()) { // Not local (Production server)
        $info["host"] = "localhost";
        $info["user"] = "xxx";
        $info["password"] = "yyy";
        $info["dbname"] = "production_db";
    } else { // localhost (Test server)
        $info["host"] = "localhost";
        $info["user"] = "abc";
        $info["password"] = "xyz";
        $info["dbname"] = "local_db";
    }
}

daveb
User
Posts: 32

Post by daveb »

I have re-checked the sample code and use:

function Database_Connecting(&$info)
{
        $info["host"] = "localhost";
        $info["user"] = "root";
        $info["port"] = "3306";
        $info["password"] = "";
        $info["dbname"] = "fastest0417";		
   var_dump($info);
}

Var_dump shows that the fields are updated, but the project continues to use the database named in the project options. The second database was created using the copy function of phpadmin and is a second subfolder in the xampp\mysql\data folder. I have restarted the browser to clear any cache but there is no difference


arbei
User
Posts: 9389

Post by arbei »

For the "production" environment, you better check if you have set up connection info in the advanced settings Connection info of production server (JSON).


Post Reply