Friday, January 29, 2010

Database handle in PHP-mysql

This is the two line code i use to connect to database through PHP:

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

The great thing about this code is that once dbhandle is created then any call to mysql_connect will reuse the old dbhandle. This is very nice abstraction provided by PHP-mysql connector. I dont know if this is same with other connection object or not...

SJ

No comments:

Post a Comment