function escape($str)
{
// If there is no existing database connection then try to connect
if (!isset($this->dbh) || !$this->dbh) {
$this->connect($this->dbuser, $this->dbpassword, $this->dbhost, $this->dbport);
$this->select($this->dbname, $this->encoding);
}
if (get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return $this->dbh->escape_string($str);
}