Accessing global variables within functions in PHP

Posted by st3 on Stack Overflow See other posts from Stack Overflow or by st3
Published on 2010-05-18T22:29:55Z Indexed on 2010/05/19 12:50 UTC
Read the original article Hit count: 210

Filed under:
|
|
|

There are multiple times in one page where I need to connect and subsequently query a MySQL database, yet my code won't let me. I think it might be something to do with how my files are nested but it makes no sense. I am opening the SQL connection in the header file. The top of the offending page looks like the following:

<?php 
$page_title = 'Dashboard';
include('templates/header.inc'); // includes a 'require_once('mysqli_connect.php') and a small query to the database;
require_once('includes/functions.php');
require_once('includes/dashboard_sql.php'); // Contains functions which connect to database (which are failing.)
?>

I get the PHP error

Notice: Undefined variable: dbc in /Library/WebServer/Documents/pediatory_site/includes/dashboard_sql.php

Where $dbc is the database connection defined in mysqli_connect.php.

If anyone could help me out that would be great.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql