View Single Post
Old 01-08-2009, 11:56 PM   #13 (permalink)
sarmenhb
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

you dont really have to use oop the whole purpose of it is to reuse code on multiple pages rather than having to retype a bunch of things.

OOP is just a bunch of functions places all together and work together.

here is an example
i kind of forgot how its written but ill try and explain

Code:
Class phpConnect {

var host 
var login;
var password;
var dbname;

function connect_info{) {
//$this->host is the same as writing phpConnect->host
//its much shorter to write $this rather than the whole class name

$this->host = "localhost";
$this->login = "username";
$this->password = "password";
$this->dbname = "somedb";
}

function connect() {

return mysql_connect($this->host,$this->username,$this->password);
return mysql_select_db($this->dbname);
}

$con = new phpConnect();
$con->connect;
maybe i wrote it wrong but someone correct me if i did but basically now you cna just include this page onto every page that you want the connection to occure then again you could of made it shorter by just doing

Code:
mysql_connect("localhost","root","password");
mysql_select_db("dbname");
the purpose of the class is to instantiate an existing bunch of functions to reuse them in seperate ways instead of using it in one way. my best suggestion would be to checkout as much as classes as possible , give it 1 month, 5 months , 1 year, untill you see its purpose. you dont need to rush into it because you can do the same thing in fewer lines. you will see its purpose once it clicks into you, once it does it will make ur life easier.

as for me, this whole time that i've been doing php i havent used classes yet but i should because i need to create a few tools with classes so all i need to do is type one line of code the next time and all my hours spent on making something will be cut down to 1 minute!.
__________________
no signature set
sarmenhb is offline  
Reply With Quote