Hi,
I am following Kevin Yank’s book ‘PHP and MYSQL Novice to Ninja’. I am a novice.
He appears to suggest placing the database connection code in index.php which would be in the public directory on the server. Is this a good idea?
I would prefer to place this in a private directory on my server. Would it be secure to then use an ‘include’ to call this file from index.php? I was hoping to use an array item $_CONF[‘path’], concatenated to the connect.php This would hopefully make it more difficult to find the path to connect.php
The problem is how could I define $_CONF[‘path’] in the private directory so that this path could not be seen? If it is given a value in a file in private the full path to that would have to be given in a public file.
index.php
include $_CONF['path'] . "connect.php";
connect.php
<?php
try
{
$pdo = new PDO('mysql:host=localhost;dbname=ijdb', 'ijdbuser', 'mypassword');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "utf8"');
}
catch (PDOException $e)
{
$output = 'Unable to connect to the database server.';
include 'output.html.php';
exit();
}
$output = 'Database connection established.';
include 'output.html.php';
Any help would be greatly appreciated.
Thanks,
Shane