06-02-2008, 01:00 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
|
A cute mysql function :)
Well, as i work on my current project, i made up a nice little mysql connect function:
PHP Code:
function connect_to_db($linkname) { global ${$linkname}; $host = 'localhost'; $user = ''; $pass = ''; $name = ''; if (${$linkname} = mysql_connect($host, $user, $pass)) { if (mysql_select_db($name, ${$linkname})) { return true; } else { return false; } } else { return false; } }
Usage is really simple to, a little snippet could be:
PHP Code:
if (connect_to_db('link1')) { echo('Yes, id: ' . $link1); } else { echo('No.'); }
I for one think it is nice, ofcause it can't compare to a complete DAL but for a little project on a default LAMP server it is nice :)
|
|
|
|