MorkaLork Development

Interesting stuff I've picked up over the years...


2009-04-16 18:11:19 | 186 views | connect connectdb mysql php function

ConnectDB() is a small function that you should have in one way or another if you're working with a database. Instead of entering code to create an uplink to your database eachtime, you simply just have a script to do it for you.

The use of this function would be:




That's it.

The function looks like this:

function ConnectDB()
$host="MyHost"; // Host name, could be localhost, an IP or a URL
$username="MyUsername"; // Mysql username
$password="MyPassword"; // Mysql password
$db_name="MyDB"; // Database name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


Article comments

Feel free to comment this article using a facebook profile.

I'm using facebook accounts for identification since even akismet couldn't handle all the spam I receive every day.