I want to convert severals rows after PDO request but I can't display result on my page.
This is for use with a rubimotion app
there is my php code:
<?php
//to see what return request in my php page
header('Content-type: text/html; charset=utf-8');
try {
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=IP;dbname=NAME','USER','PASS');
$reponse = $bdd->prepare("SELECT * FROM table WHERE id = 1");
$reponse->execute(); #this request return severals rows
$nb = $reponse->rowCount();
if($nb > 0){
$json = json_encode( $reponse->fetchAll( PDO::FETCH_ASSOC ) );
echo $json;
}
}
catch (Exception $e) {
echo "Connexion échouée : " . $e->getMessage();
}
?>
But I have a white page and in the console the response is empty.
Whats wrong ?
I tryed many option however I have many errors like
- array to string convertion
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
thanks ! And sorry for the mistakes I am french
$pdo_options, but it isn't used in your connection?