The following code results to an error
Call to a member function real_escape_string() on a non-object
But if place the ($this->conn = new mysqli
)
inside the escapedString($string)
method, it will run without error. What
can be the reason of the error? Thank you.
private $onMagicQuote;
private $conn;
function __contruct(){
$this->conn = new mysqli($this->host, $this->uname, $this->pass, $this->db)
or die('Problem in connection');
if(get_magic_quotes_gpc())
$this->onMagicQuote = true;
else
$this->onMagicQuote = false;
}
function escapedString($string){
if($this->onMagicQuote)
return $string;
else
return $this->conn->real_escape_string($string);
}