3
I’m trying to make a SELECT through PHP mysqli, but it’s returning null in all parameters of the object returned by $mysqli->query($sql).
Even so it returns the rows I selected from the table, only some values have come null also:
Follows 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 tried to see if it could be some Mysql syntax error, but I played the query directly in the database and it worked normally. I had the same problem with another code I was doing yesterday and I couldn’t fix it. It’s weird, considering I always do it the same way and it works...
Where am I wrong? Someone can help me?
Thank you.
Yes, return in JSON format to use in Ajax.
– carol_caires
I think that’s right, Guilherme. I’m bringing the result in PHP array instead of JSON and it’s coming back right. Do you know why this might be happening? I’ve always used the conversion of arrays to JSON and never had this problem.
– carol_caires
Edited. I put the last two indexes only for debug purpose.
– carol_caires
Only one doubt, in the table the fields
EmailCounterpart
,Provider
,Balance
andDirection
are blank?– Guilherme Nascimento
The
EmailCounterpart
,Provider
andDirection
usually comes in white even. But theBalance
and theMessage
that are coming null in JSON always comes filled.– carol_caires
William, I appreciate your help. As our colleague Bruno said below, the problem was that I was sending a data that is not in UTF-8 to json_encode, so it was not working. I managed to solve :)
– carol_caires
Good, I wish you success in your project
– Guilherme Nascimento