Are there any potential pitfalls to consider when storing PHP files online for accessing SQL database values?

One potential pitfall to consider when storing PHP files online for accessing SQL database values is the security risk of exposing sensitive information, such as database credentials, in the code. To solve this issue, it is recommended to store sensitive information in a separate configuration file outside of the web root directory and include it in the PHP files using include or require statements.

<?php

// config.php
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASS', 'password');
define('DB_NAME', 'database');

// connection.php
require_once('config.php');

$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// query.php
require_once('connection.php');

$sql = "SELECT * FROM table";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "Column1: " . $row["column1"]. " - Column2: " . $row["column2"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();

?>