Instead of saving the database connection in the session, you should make the connection calls in a separate file, such as db.php, and then require it from each of your scripts. For example, put your connection in db.php:
mysql_connect('...', '...', '...'); mysql_select_db('...');
and then enter it in login.php:
require('db.php'); $res = mysql_query('...');
Then you can do the same for each PHP file that needs access to the database, and you only have to change the credentials of access to the database in one file.
source share