Forum Moderators: coopster
I think it is best for me to start out and create my own classes so maybe the oo will just click in my brain.
I've come up with this for mysql connect and select db...
class mySQL {
public $dbHost = "";
public $dbUser = "";
public $dbPass = "";
public $dbName = "";
public $dbLink = "";
public $database = "";
function mySQL() {
$this->dbHost = 'localhost';
$this->dbUser = 'root';
$this->dbPass = '';
$this->dbName = 'testdb';
}
function myConnect() {
$dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
return $dbLink;
}
function myDatabase() {
$database = mysql_select_db($this->dbName);
return $database;
}
}
And then I call it in my script...
$myTest = new mySQL;
$link = $myTest->myConnect();
$database = $myTest->myDatabase();
Am I going about this right?
Thanks,
~RD
I would suggest that as you build the class up, the constructor function handles the database connection and selection, purely for simplicity of coding scripts that implement the mysql class. :)
functions myConnect and myDatabase are missing some '$this->'s though..
So I guess you mean...
function myConnect() {
$this->dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
return $this->dbLink;
}
function myDatabase() {
$this->database = mysql_select_db($this->dbName);
return $this->database;
}
I'm I on the right trach now?
I'm so use to creating varibles...
Thanks
RD
by defining debug as empty via = ""; and in my script going with .= and output is success etc...
class mySQL {
public $dbHost = "";
public $dbUser = "";
public $dbPass = "";
public $dbName = "";
public $dbLink = "";
public $database = "";
public $dbclose;
function mySQL() {
$this->dbHost = 'localhost';
$this->dbUser = 'root';
$this->dbPass = '';
$this->dbName = 'testdb';
}
function myConnect() {
$this->dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
return $this->dbLink;
}
function myDatabase() {
$this->database = mysql_select_db($this->dbName);
return $this->database;
}
function myClose(){
$this->dbclose = mysql_close($this->dbLink);
}
}
and at end of my script I add...
$myTest->myClose();
any suggestions?
am I on the right track?
One more question...
Can I access something inside the fuctions?
I mean by creating new (class)
I'm making the object $var->fuction and whats in fuction runs...
Is all accessed like this or can I access $var->func->var2?
Thanks,
RD
PS: I've never used classed because I've seen how slow CMS's can get etc...
Also by testing speeds of DB class handlers etc I've always found the few simple lines are twice as fast then having to go through thousands of lines of code etc...
So I think each applications needs to be unique and stripped of every line possible...
Thanks
[edited by: RDWest2005 at 1:38 am (utc) on Aug. 13, 2007]