In my index.php file I have included my db_connect.php file.
If I include another file (page1.php) in index.php, can I call my DB::query()
function in page1.php? I must include db_connect.php to page1.php too?
In my index.php file I have included my db_connect.php file.
If I include another file (page1.php) in index.php, can I call my DB::query()
function in page1.php? I must include db_connect.php to page1.php too?
You may want to include_once('db_connect.php');
or even require_once('db_connect.php');
in any file that you are including that will need to make a database connection. Using these methods the file will not be loaded again if already included with another file.
include_once()
and require_once()
act about the same, but they handle errors differently. You can find a good explanation of that here: Difference between require, include, require_once and include_once?