Re: Coding Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jason Wong wrote:
On Monday 06 December 2004 14:19, Rory Browne wrote:

If I'm not mistaken Al wanted to return something if the thing failed,
without having to put it inside an if_block.

I'm watching this with curiosity, because return is a language
construct, and not a function, or anything that has a value.


You can have:

  ... OR $error = "Oh dear";

But the say I see it, eventually, somewhere in your code you need to test for it. Essentially you're just moving the test somewhere else.



Essentially, I'm creating warning reports for my users, not code errors. The users can then email the warnings to our webmaster.

Here's what I ended up with:


@$host_link= mysql_connect($host, $user, $pw) OR $values['msg']= $values['msg'] . "Could not connect to mySQL host ";

if($host_link){
$db_link= mysql_select_db($db, $host_link)
OR $values['msg']= $values['msg'] . "Could not connect to mySQL DB: $db";
}

if($host_link AND $db_link){
$result = mysql_db_query($db,"select count(*) from $table")
OR $values['msg']= $values['msg'] . "Could not connect to mySQL Table: $table";
}
if($host_link AND $db_link AND $result){

$values['num_records'] = ($result>0) ? mysql_result($result,0,0) : 0;

}//end if

return $values; //tech notes and db table stuff

The calling page echoes $values['msg'] in nice red text.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux