PHP - returning multiple states, not just true/false

diablo3qlz

New Member
I have a conceptual problem to do with PHP classes and error handling.. Below is a basic class demonstrating my issue. A function to create a database record exists named "domain_create". This function calls a secondary function to ensure that the domain to be created does not already exist within the database table. In the past I have always used true or false to reflect if the function had found a record, but that creates a flaw in my logic.. Records are inserted when the domain_lu function returns false, however should be done if an error is encountered such as the select failing? Returning false would cause the create function to believe nothing has been found and continue with the create process.. My question is how should multiple states be reflected in this scenario? Is there a "best practise" for this scenario? \[code\]<?phprequire_once('auth.base.class.php');require_once('mysql.class.php');class auth extends base{ public function __construct() { parent::__construct(); } /* * User */ public function domain_create($args='') { if ( domain_lu($args['dname']) === FALSE ) { return $error['Domain already in use']; } } /* * Domain */ private function domain_lu($dname) { $sql = "SELECT name FROM domain WHERE name = '$dname'"; $this->_mysql->SQLQuery($sql); if ($this->_mysql->numRow() > 0) return true; else return false; }}?>\[/code\]
 
Back
Top