Good day!
I have a website deployed in a free web-hosting server. Recently, I cannot access my SQL and receive this warning: too many connections.
MY CODES:
In order to access mysql, i created a config.php file.
<?php
// save this as config.php
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASSWORD', 'password');
define('DB_DATABASE', 'pascual4_eventpost');
$conn=mysql_pconnect(DB_HOST, DB_USER, DB_PASSWORD)
or die ("Error connecting to database");
mysql_select_db(DB_DATABASE)
or die ("Error: Cannot access database");
?>
So If ever I need to access my database. I just call require("config.php");
I've read somewhere before that mysql connections automatically closes when the script is done. That's why I don't put any mysql close connection code on my PHP pages. Or do I still need to close it manually and input mysql_close($conn);
on every page?
So I restarted my PC and flush my dns. Luckily, now I can access my mysql database but it is very slow. Maybe because I am using a free-web hosting? But, on my part, is there a way where I can speed-up my mysql connection and queries. What Validations can I include on the above code so that I could improve the performance of my mysql connection? Thank you.