Mega Code Archive

 
Categories / Php / MySQL Database
 

I got tired of typing the connection code for MySQL on every PHP

page, so we built this simple little function. <? // CONSTANTS define("DBSERVER", "www"); define("DBUSER", "LimitedUser"); define("DBPASS", "N0tAPa55w02d"); $SQL = ""; $LastError = ""; function DatabaseConnect() { global $LastError; $LastError = ""; //----------------------------- // Connect to the mysql server. //----------------------------- $dbHandle = @mysql_connect(DBSERVER, DBUSER, DBPASS); if ($dbHandle == false) { $LastError = "Unable to connect to the database server: " . mysql_error(); return false; } mysql_select_db("test"); return true; } ?>