View Single Post
Old 06-02-2008, 02:00 PM   #1 (permalink)
SpYkE112
The Contributor
 
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
SpYkE112 is on a distinguished road
Default 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 :)
SpYkE112 is offline  
Reply With Quote
The Following User Says Thank You to SpYkE112 For This Useful Post:
Wildhoney (06-02-2008)