Perte de données avec json_encode()
bonjour,
Se suis en train de développer une application Android dans le cadre d'un stage, cette application permettra des notifications sur son téléphone. Dans ce but, elle se connecte à une base de donnée distante à l'aide d'un script php et récupère un array json.
Mon problème est que la requête se termine bien et renvoi toutes les données mais la sortie json_encode() contient des champs null.
Quelqu'un peut-il m'éclairer?
Voici le script:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| $link = new mysqli("xxxx", "xxxx", "xxxx", "xxxx");
if (!$link) {
die('Erreur de connexion (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
$result = $link->query("SELECT * FROM notifications") ;
$output = array();
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$output[]=$row;
}
var_dump($output);
echo '<br><br>';
echo json_encode($output);
$link->free();
$link->close(); |
Et la sortie de ce script:
Code:
1 2 3
| array(3) { [0]=> array(4) { ["idNotification"]=> string(1) "1" ["texteNotification"]=> string(37) "Elles sont belles mes patates à l'eau" ["idRestaurateur"]=> string(1) "1" ["titre"]=> string(18) "Promo chez Bob !!!" } [1]=> array(4) { ["idNotification"]=> string(1) "2" ["texteNotification"]=> string(88) "Aujurd'hui: escargot de bourgogne solitaire avec ses zestes de truffe en sauce au safran" ["idRestaurateur"]=> string(1) "2" ["titre"]=> string(18) "Promo Plat du jour" } [2]=> array(4) { ["idNotification"]=> string(1) "3" ["texteNotification"]=> string(29) "Encore une belle notification" ["idRestaurateur"]=> string(1) "2" ["titre"]=> string(16) "notification n°3" } }
[{"idNotification":"1","texteNotification":null,"idRestaurateur":"1","titre":"Promo chez Bob !!!"},{"idNotification":"2","texteNotification":"Aujurd'hui: escargot de bourgogne solitaire avec ses zestes de truffe en sauce au safran","idRestaurateur":"2","titre":"Promo Plat du jour"},{"idNotification":"3","texteNotification":"Encore une belle notification","idRestaurateur":"2","titre":null}] |