I'm trying to do a SELECT through PHP's mysqli, but it's returning null in all parameters of the object returned by $ mysqli-> query ($ sql) >.
ItstillreturnstherowsthatIselectedfromthetable,butsomevaluescomenullalso:
Follow my code:
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$cell_number = $_POST['cell'];
$sql = sprintf("SELECT * FROM SMS WHERE Number LIKE '%%%s%%'", $cell_number);
$query = $mysqli->query($sql) or die($mysqli->error.__LINE__);
while($row = $query->fetch_assoc()) {
$result[] = $row;
}
die(json_encode(array('resultado' => $result, 'debug' => $query, 'sql' => $sql)));
I've tried to see if it could be some MySQL syntax error, but I threw the query directly into the database and it worked fine. I had the same problem with another code I was doing yesterday and could not resolve. It's strange, considering that I always do the same thing and it works ...
Where am I going wrong? Can anyone help me?
Thank you.