28 lines
749 B
PHP
28 lines
749 B
PHP
|
<?php
|
||
|
// Load the configuration file
|
||
|
$configFilePath = 'config.cfg';
|
||
|
$config = parse_ini_file($configFilePath, true);
|
||
|
|
||
|
// Check if the mysql section exists in the config file
|
||
|
if (!isset($config['mysql'])) {
|
||
|
die('MySQL configuration not found in config.cfg');
|
||
|
}
|
||
|
|
||
|
// Extract MySQL connection parameters from the config file
|
||
|
$host = $config['mysql']['host'];
|
||
|
$username = $config['mysql']['username'];
|
||
|
$password = $config['mysql']['password'];
|
||
|
$database = $config['mysql']['database'];
|
||
|
|
||
|
// Create a connection
|
||
|
$conn = new mysqli($host, $username, $password, $database);
|
||
|
|
||
|
// Check the connection
|
||
|
if ($conn->connect_error) {
|
||
|
die('Connection failed: ' . $conn->connect_error);
|
||
|
}
|
||
|
|
||
|
// Optionally, close the connection when done
|
||
|
// $conn->close();
|
||
|
?>
|