[nycphp-talk] Accessing a method from one class in another
Randal Rust
randalrust at gmail.com
Sat Jan 14 13:16:19 EST 2006
On 1/14/06, Kenneth Downs <ken at secdat.com> wrote:
> So first you have to tackle the issue of scoping the connection to the DB.
> I myself use a global connection handle that is opened at request start
> and closed at request end.
Here is what my connection class looks like:
<?php
class DB {
var $conn;
//constructor
function DB (){
//include 'adodb/adodb.inc.php';
$this->conn =& ADONewConnection('mysql');
if($ip=$_SERVER['REMOTE_ADDR']=='127.0.0.1'){
$conn=$this->conn->PConnect('localhost','','','osboc');
}
else {
//$conn=$this->conn->PConnect('localhost','','','');
$conn=$this->conn->PConnect('localhost','','','_');
}
return $conn;
}
}
?>
> But if this is not appropriate to your context, the
> you will have to obtain the handle and then pass it around to those
> routines that need it.
Which is what I'm doing now. Whether or not it's appropriate, I don't
know. I just know that it works.
> Perhaps there should be data retrieval
> routines that pull information from a database, and separate rendering
> routines that turn retrieved data into HTML.
I try as much as I can to keep my methods from producing HTML, but
most of them strictly make calls to the DB and return information, or
return something based on the action of another method.
--
Randal Rust
R.Squared Communications
www.r2communications.com
More information about the talk
mailing list