I am developing a system that searches for products on a data base by description, everthing worked fine, I had no problem during my sentences, the problem came today when I tried searching using an Emoji as input, it did only not returned an empty array as it happens when the description doesnt match anything but it crashed my code and PHP said "Call to a member function fetch_assoc() on bool" well I then used the mysqli->errno to see what the problem was and I found out it was returning error number 2014. Here's part of my code
<?php
function select($connection, $query, $dataType, $data) {
$preparedQuery = $connection->prepare($query);
if ($preparedQuery === false) {
//You may ignore this since it's sending messages in another language to the user
//All of my responses are sent in JSON format to the client
$error = $connection->error;
return '{"exito":"no","motivo":"Error en la consulta: ' . $error . '","consulta":"' . $sentencia . '"}';
}
if (count($data) > 0) {
$preparedQuery ->bind_param($dataType, ...$data);
}
$preparedQuery->execute();
$i = 0;
$results= $preparedQuery->get_result();
$registros = [];
if($results=== false){
//This is where I found out I was getting the 2014 error
echo $connection->errno;
}
while ($temporal = $results->fetch_assoc()) {
$registros[$i] = $temporal;
$i++;
}
//There's more code below
}
function connect() {
$server = "localhost";
$user = "root";
$password = "";
$db = "electrodomesticos";
$connection= new mysqli($server, $user, $password, $db) or die("Error en la conexion a Mysql");
$connection->set_charset("utf8");
return $connection;
}
$connection = connect();
$description = $_POST["description"];
$query = "select * from products where descripcion like ?";
echo select($connection, $query, "s", ["%" .$description . "%"]);
That is not exactly how I've written my code, but in essence it is something like that, Why would my code crash and return error 2014?
I would really appreciate if somebody help mewith this, thank you in advance