I am working on a project in which I am using mysqli extension. I have made mysql connection in a PHP class called Connect.class.php like this -
// connect to db
public function connect()
{
$this->con = @mysqli_connect($this->db_host, $this->db_username, $this->db_password, $this->db_name) or die("Couldn't connect! " . mysqli_connect_error());
return $this->con;
}
And I have one another file called functions.php in which I am sanitizing the input data like this -
// filter user input data
function filter_data($input)
{
$sanitized_data = mysqli_real_escape_string(connection, htmlspecialchars(trim($input), ENT_QUOTES, "UTF-8"));
return $sanitized_data;
}
Now the above code will not work since it has not correct connection parameter. I am not understanding how can I provide it proper connection that is made from my PHP class Connect.class.php. Since the property of an object can not be used in a function of a separate file i.e. i cant use $this->con.
If I use simple mysql in place of mysqli then there is no problem at all since mysql_real_escape_string() doesn't need connection as a necessary parameter. So what to do in this situation?