I am currently working on a small project and, for the love of god, I cannot get this PHP class working.
The problem is, doQuery doesn't return anything nor modifies the DB when I type and INSERT or any other command here, always returns false even when called from within the class.
class CONN {
private $connection;
public function __construct() {
$this->connection = new mysqli($address, $user, $pass, $db);
if ($this->connection->connect_error) {
// Throw error here
} else {
$this->doQuery("SET NAMES 'utf8'");
}
}
public function doQuery($query){
return $this->connection->query($this->connection->real_escape_string($query));
}
}
Solved
The real_escape_string escaped even ' and hence the query could not work.
falseand log it. Not enough information here by itself.real_escape_stringon variables used inside the SQL query. I think the quotes around theutf8are getting escaped and as a result the query is invalid. Is there any errors emitted?error_log($query);inside ofdoQuery()echo $this->connection->error;inside if condition asif($this->connection->error_no){You will get the exact message if the query fails. You can paste that error here and that can get a clue.error_logoutputs1