PHP: OOP help!!
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.
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:
function Db($db_host, $db_user, $db_password, $db_name){
__construct($db_host, $db_user, $db_password, $db_name);
}
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 -
Thanks
{{ DiscussionBoard.errors[2140860].message }} -
-
<CrGeary.com/> -
Thanks
{{ DiscussionBoard.errors[2140938].message }} -
-
Christopher Airey -
Thanks
{{ DiscussionBoard.errors[2141189].message }} -
-
Aaron Sustar -
Thanks - 1 reply
{{ DiscussionBoard.errors[2162444].message }}-
mgkimsal -
Thanks
{{ DiscussionBoard.errors[2164310].message }} -
-
-
<CrGeary.com/> -
Thanks
{{ DiscussionBoard.errors[2168090].message }} -