This handy little script can be used as a function as required, or in an include. I have used this on virtually every site that uses a a database connection.
<?php $DBHOST = ' '; $DBNAME = ' '; $DBUSER = ' '; $DBPASSWORD = ' '; function dbconnect() { global $DBHOST, $DBNAME, $DBUSER, $DBPASSWORD, $DBERROR; if (@mysql_pconnect($DBHOST, $DBUSER, $DBPASSWORD)) { if (@mysql_select_db($DBNAME)) { return true; } else { echo "ERROR: Cannot select database."; exit; } } else { echo "ERROR: Cannot connect to database server."; exit; } } ?> |
Write a Comment
Let me know what you think?