New here, and PHP's a new language to me. I'm trying to develop a web app. To keep things secure, I'm trying to save my database login credentials in a simple ini file (called db.ini).
1) My system is running Ubuntu 18.04. I've installed LAMP
2) The script, which updates a database via mysqli_connect and mysqli_query, works fine when I have login credentials in the myqli_connect script pasted below. Note, for troubleshooting I'm echoing a message upon successful connection:
$db = 'my_db';
$db_use = 'my_root_user';
$db_pass = 'my_password';
$db_host = 'localhost:3306';
$conn = mysqli_connect($db_host, $db_use, $db_pass, $db);
if(! $conn)
{die('Could not connect connect: ' . mysqli_connect_error()) ;
} else
{echo ("Success");
}
3) I created a db.ini file for security reasons. Though I plan to move it later, I've stored in in the same directory as my .php script: (\var\www\html\my_site).
Here's how the .ini reads
[database]
host = localhost:3306
username = my_root_user
password = my_password
dbname = my_database
3) I have tried to parse this file via the following methods. All have failed at print_r, let alone opening the database, so they're not opening.
parse_ini_file('db.ini') // failed
parse_ini_file('/var/www/html/my_site/db.ini'); // failed
4) I've confirmed that the file exists in my php using the following code.
$filename = 'db.ini';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
5) Ergo, the import does not appear to be working on my setup (Ubuntu LAMP).
6) On a related not, I tried this as a "require", and saving the variables as db_config.php as well. This did not link up either even though the file exists.
Needless to say, I'm at the end of my rope. Any suggestions? I've a feeling it's a configuration issue, where the script is walled off from communicating with other files on either Apache or my Linux, but have no experience on where to go.