Forum Moderators: coopster
if(file_exists('config.php'))
{
require_once('config.php');
}
$db_host = $config['db_host'];
$db_database = $config['db_database'];
$db_username = $config['db_username'];
$db_password = $config['db_password'];
<?php
$config = array();
/*** site details ***/
$config['site_name'] = "This Is A Test Website";
/*** database details ***/
$config['db_username'] = "username";
$config['db_password'] = "password";
$config['db_database'] = "website";
$config['db_host'] = "127.0.0.1";
print_r($config)
?>
function menu_links()
{
try
{
if(file_exists('config.php'))
{
require_once('config.php');
}
else
{
die('File not found.');
}
print_r($config);
$links = "";
$link_type = "menu";
$dbh = new PDO("mysql:host=".$config['db_host'].";dbname=".$config['db_database']."", "".$config['db_username']."", "".$config['db_password']."");
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->prepare('SELECT link_title, link_location FROM tbl_site_links WHERE link_type = ?');
$stmt->bindParam(1, $link_type);
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach($stmt->fetchAll() as $array)
{
$links .= '<li><a href=\"'.$array['link_location'].'\">'.$array['link_title'].'</a></li>';
}
return $links;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
catch(Exception $e)
{
echo $e->getMessage();
}
}
I'm using the below code inside a custom function and when debugging the code, the $variables always return null.