Okay, well this is the first time i have really used any OOP in PHP, im surprised that i havn't even touched on it. Anyway, the problem is i dont totally understand what i am doing, i think i got the basics sort of figured out, this is what i came up with when i try making a DB class which at the moment connects to the database.
PHP: OOP help!!
7
Okay, well this is the first time i have really used any OOP in PHP, im surprised that i havn't even touched on it.
Anyway, the problem is i dont totally understand what i am doing, i think i got the basics sort of figured out, this is what i came up with when i try making a DB class which at the moment connects to the database.
Is this right?, Is there anything here that i should have, or i shouldn't have?
--
Also, i read that __contruct() doesnt work in PHP 4, but i can make a function with the same name as the class, so can i do this:
Or do i have to do:
Or something else?
---
I figured if i just dive into this and try making something, that i would learn it faster.
Anyway, the problem is i dont totally understand what i am doing, i think i got the basics sort of figured out, this is what i came up with when i try making a DB class which at the moment connects to the database.
PHP Code:
class Db {
function __construct($db_host, $db_user, $db_password, $db_name){
//* Connect to MySQL (@ = Suppress Errors)
$this->db_handler = @mysql_connect($db_host, $db_user, $db_password);
if(!$this->db_handler)
echo "Didn't Work";
else
echo "Did Work";
}
}
$new = new Db('localhost', 'root', '', 'test');
--
Also, i read that __contruct() doesnt work in PHP 4, but i can make a function with the same name as the class, so can i do this:
PHP Code:
function Db($db_host, $db_user, $db_password, $db_name){
__construct($db_host, $db_user, $db_password, $db_name);
}
PHP Code:
function Db($db_host, $db_user, $db_password, $db_name){
$this->__construct($db_host, $db_user, $db_password, $db_name);
}
---
I figured if i just dive into this and try making something, that i would learn it faster.
- Christopher Airey
- <CrGeary.com/>
- Christopher Airey
- Aaron Sustar
- [1] reply
- mgkimsal
- <CrGeary.com/>
Next Topics on Trending Feed
-
7