last day (15 days later) » 

7:34 PM
0
A: PHP PDO SQL query

medaUse this code: $stmt = $con->prepare($_sql); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); var_dump($rows); echo json_encode(array('Order'=>$rows)); and if the value is hardcoded in the query you don't have to prepare $stmt = $con->query($_sql); $rows = $stmt->fetchAll(PDO::FET...

 
it shows two arrays which are right!! :) But the json_encode give a null back :(
 
@user3493797 sorry typo check again, use $rows when you encode
 
Thanks, but there are these 2 arrays from var_dump. But Json_Encode shows nothing.
 
can you update your question with the dump, I dont see why it fails unless you have bad encoding characters
@user3493797 json_encode will only fail when the strings are not encoded properly
 
I edited my question and the answer looks a bit weird, maybe thats my problem.
 
7:34 PM
@user3493797 are you here
 
yes im here now
 
is everyhting utf8 encodeed
 
in my table is everything uft8 encoded, or should I do it also in my php file?
ok ok ok :D
i got it now
 
yes everywhere
json_encode only work with utf 8
 
I forgot to encode utf8 in my pdo while I call the data base: $db = new PDO("mysql:host=".$db_host.";dbname=".$db_name,$db_user,$db_password,array(PDO::‌​MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
 
7:37 PM
oh okay
does it work now
 
Thanks! :)
 
Ok remember to vote my answer up @user3493797
I gave you +1 good question!
 
done, thank you!
 

last day (15 days later) »