Is this a valid PHP function call?

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

Post Reply
LonelyProgrammer
Forum Contributor
Posts: 108
Joined: Sun Oct 12, 2003 7:10 am

Is this a valid PHP function call?

Post by LonelyProgrammer »

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 »

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 »

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
Post Reply