Re: mysql connect function in my class

From: Date: Thu, 15 Apr 2004 05:56:00 +0000
Subject: Re: mysql connect function in my class
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-183422@lists.php.net to get a copy of this message
makes since... i think would i would probably do is define the error/errormsg stuff at the beginning of the class that way all functions can use it?? class DbConnection { var $ErrorNumber; var $ErrorMsg; function Connect(.....){ $link=mysql_connect(...); if(!$link){ $ErrorNumber=mysql_errno(); //and the msg itself if we want $ErrorMsg=mysql_error(); return false;} else{return $link;}} or however the best way goes for that... ----- Original Message ----- From: "Curt Zirzow" <czirzow@dotgeek.org> To: <php-general@lists.php.net> Sent: Thursday, April 15, 2004 1:35 AM Subject: Re: [PHP] mysql connect function in my class > * Thus wrote Andy B (aborka1@wmis.net): > > hi.... > > i have this function inside a class that im writing that eventually i want > > to put inside a package of my own... the function goes like this: (comment > > block included): > > > > /** > > *function Connect: open connection to database. > > * > > *@param string $host mysql hostname to connect to > > *@param string $mysqluser name of the mysql user to login with > > *@param string $mysqlpwd the users password for mysql server > > *@return resource|false > > */ > > > > function Connect($host, $mysqluser, $mysqlpwd){ > > $link=mysql_connect($host, $mysqluser, $mysqlpwd) > > if(!$link){ return false; } > > else { return $link; }} > > > should i keep it like this or is it better for the function itself to deal > > with error handling at the same time? i.e. should it return an error > > message/number or something of that sort or give the returned resource over > > to some other function that deals with errors.... > > A standard database layer will return false, and set a error code > and error message property, so the application using the class can > do something about it. > > > if (! $link = mysql_connect($host..) ) { > $this->error = mysql_errno(); > $this->error_msg = mysql_error(); > return false; > } > ... > > Then in the application: > > if (! $dbh = $db->Connect(blah...) ) { > echo $db->error, ': ', $db->error_msg; > exit; > } > > > > Curt > -- > "I used to think I was indecisive, but now I'm not so sure." > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#183422) next »