PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
LonelyProgrammer
Forum Contributor
Posts: 108 Joined: Sun Oct 12, 2003 7:10 am
Post
by LonelyProgrammer » Sun Mar 14, 2004 4:57 am
Code: Select all
function connectToDB(&$errorMessage = "" )
{
$link = mysql_connect( ... )
if (! $link) $errorMessage = "Failed to connect to mysql";
}
connectToDB();
LonelyProgrammer
Forum Contributor
Posts: 108 Joined: Sun Oct 12, 2003 7:10 am
Post
by LonelyProgrammer » Sun Mar 14, 2004 5:14 am
Gah, I stupidly post in the wrong forum. Can someone help to move the post? Apologies in advance!
Black Unicorn
Forum Commoner
Posts: 48 Joined: Mon Jun 16, 2003 9:19 am
Location: United Kingdom
Post
by Black Unicorn » Sun Mar 14, 2004 7:25 pm
I'd only make one modification; Try instead of
...
if ($link) $errorMessage = "Failed";
...
Something like this:
if (!$link) return false;
else return true;
This way, you could do something like this:
$x = connectToDB();
if (!$x){echo("Failed! Help!");}
Best of coding,
Rage