Dizzizit
-
Posts
2 -
Joined
-
Last visited
Posts posted by Dizzizit
-
-
I don't know why it won't work.. as the topic titles says that I am trying to pass a mysqli object to a property in another class but it keeps me getting an error.
here's the code for the mysqli object that i want to pass to another class
class ConnectMe2Db { public $dbname = 'somedatabase'; public $dbuname = 'root'; public $dbpass = ''; public $dbhost = 'localhost'; function __construct() { $mysqli = new mysqli($this->dbhost,$this->dbuname,$this->dbpass,$this->dbname) or die ('ERROR: '.$mysqli->connect_errno); return $mysqli; } # OTHER CODES... }
and here is the class that i want the Mysqli object to pass to:
class DatabaseUsers { private $dbconnection; function __construct() { $this->dbconnection = new ConnectMe2Db();#mysqli object will be passed to this attribute '$dbconnection' } public function session($username, $password) { $UserName = mysqli_real_escape_string($this->dbconnection,$username); $Password = mysqli_real_escape_string($this->dbconnection,md5($password)); $querry = "SELECT * FROM trakingsystem.login WHERE username='$username' and password='$password'"; $result = mysqli_query($this->dbconnection,$querry) or die (mysqli_error($this->dbconnection)); $count = mysqli_num_rows($result); $row = mysqli_fetch_array($result); if ($count > 0) { #some code here } } #some other code here }
and this outputs 4 errors:
#outputs 2 of these: Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli
and some
mysqli_query() expects parameter 1 to be mysqli mysqli_error() expects parameter 1 to be mysqli
is there something wrong with the logic that I've made? please help thanks
passing mysqli object to an attribute of another class HELP!
in PHP Coding Help
Posted
thanks for the great insights dude.. I'll go ahead and sort this one out hopefully