php - Encoding json from database -


I know that it has been asked thousands of times, but I still can not wrap my head around it. Here comes it: I want to convert my database data to Jason in sign language.

I was working under the old version of phs using MSQL_connect, etc. in place of mysqli instead of mysqli I have updated the server yesterday and I can not work with mysqli

This is my code, nothing is returning, not zero, no empty bracket, nothing.

  & lt ;? Php $ mysqli = new mysqli ("$ host", "$ username", "$ password", "$ db_name"); $ MyQuery = "SELECT * myTable ORDER to date DESC LIMIT 4"; $ Result = $ mysqli- & gt; Query ($ myQuery); $ Data = array (); While ($ line = mysqli_fetch_assoc ($ result)) {$ data ['nameOfArray'] [] = $ line; } Echo json_encode ($ data); $ Mysqli- & gt; near (); ? & Gt;   

I should look something like

  "nameOfArray": [{object}, {object}, {object}]   

The strange thing is, ik was working properly using the old methods, which I had removed (very stupid, honestly)

So hopefully someone is right Can tell in the direction. Thank you very much in advance.

EDIT: When I make a print_r, I see the data, so it has to do JSN with encoding, mysql bit is covert. I also get some answers using jsonSerializer, but I can not imagine that it needs to be very difficult to be very difficult.

   fetch_assoc ()) {$ data ['nameOfArray'] [] = $ line; } Echo json_encode ($ data); $ Mysqli- & gt; near (); ? & Gt;    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -