I am writing a simple app for a school project that is not too big. I have the following files:
signup.php
login.php
view_photos.php
that have the following in common: they connect to a database and execute queries. In every file I find myself repeating the your typical database connection code snippet:
$mysql = new mysqli( 'localhost', 'root', '', 'imagebox');
if( $mysql->connect_errno ) {
echo "Connection failure: " . $mysqli->connect_error;
exit();
}
Is there a way to do this once in the index.php
file and pass the connection to other pages without having to repeat the same line in every page that requires a database connection?