Multiple connections to a MySQL database in a single PHP script.
- by st3
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.