• Resolved spalomba

    (@spalomba)


    Hi. I created a website for a basketbal team. In order to manage results, players, different information, related to diffent seasons and different leagues, I use an external database (MySQL) with PHP code. I am very happy with the woody solution and currently there are almost 66 scripts (PHP or Universal)
    For accessing to the database I actually have to put the parameters (Host, DB, User and PW) directely in quite each script.
    Now there are two kind of issues:
    1) should I hide the parameters for protecting my data?
    2) should I create a small snippet just for the access to the database like


    $servername = "*********";
    $user = "user";
    $password = "*************";
    $dbname = "*******";// Create connection
    $conn = @mysqli_connect($servername, $user, $password, $dbname);
    // Check connection
    if (mysqli_connect_errno())
    {
    echo "Connessione fallita: " . die (mysqli_connect_error());
    }


    or just

    $servername = "hostingmysql01.register.it";
    $user = "SP4273_user";
    $password = "SPa92113";
    $dbname = "spiox_com_campionati";// Create connection

    Should I manage the execution of a sequence of three snippets?
    [wbcr_php_snippet id=”xxxx1″ title=”access_param”]
    [wbcr_php_snippet id=”xxx99″ title=”main” mysquadra=”abcdef”]
    [wbcr_php_snippet id=”xxxx2″ title=”close_db”]
    Thanks

Viewing 1 replies (of 1 total)
  • Plugin Support rodicaelena

    (@rodicaelena)

    Hi,

    I think the most secure and efficient way to handle this, especially with 66 different scripts, would be to define your database credentials as constants in your wp-config.php file.

    By doing this, you won’t have to hardcode the password inside each snippet. If your password changes in the future, you only have to update it in one place (the config file) instead of editing all 66 snippets.

    Something like this:

    1. Add this to your wp-config.php file:

    define('EXT_DB_HOST', 'hostingmysql01.register.it');
    define('EXT_DB_USER', 'SP4273_user');
    define('EXT_DB_PASS', 'your_secure_password');
    define('EXT_DB_NAME', 'spiox_com_campionati');
    

    2. Update your snippets to use these constants: In your Woody Snippets, you can now write your connection like this:

    $conn = mysqli_connect(EXT_DB_HOST, EXT_DB_USER, EXT_DB_PASS, EXT_DB_NAME);
    
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    

    This approach is much safer because your credentials are stored in a file that isn’t accessible via the WordPress dashboard or stored in the database. Since constants are global in PHP, they will be available to every snippet regardless of which order they run in.

    Kind regards!

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.