Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]jeśli rekord zawiera polskie znaki w wyniku wyświetla "null"
@rtur
post 26.09.2012, 05:52:27
Post #1





Grupa: Zarejestrowani
Postów: 254
Pomógł: 3
Dołączył: 23.02.2006

Ostrzeżenie: (0%)
-----


Mam taki kod którym pobieram dane z bazy i wrzucam w json_encode
  1. try {
  2. $conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
  3. }
  4. catch(PDOException $e) {
  5. echo $e->getMessage();
  6. }
  7.  
  8. $return_arr = array();
  9.  
  10. if ($conn)
  11. {
  12. $ac_term = "%".$_GET['term']."%";
  13. $query = "SELECT * FROM utwory where tytul like :term";
  14. $result = $conn->prepare($query);
  15. $result->bindValue(":term",$ac_term);
  16. $result->execute();
  17.  
  18. /* Retrieve and store in array the results of the query.*/
  19. while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
  20. $row_array['id'] = $row['uid'];
  21. $row_array['value'] = $row['tytul'];
  22.  
  23. array_push($return_arr,$row_array);
  24. }
  25. }
  26. /* Free connection resources. */
  27. $conn = null;
  28. /* Toss back results as json encoded array. */
  29. echo json_encode($return_arr);

niestety nie mam pojęcia czemu jak jest polski znak w rekordzie to cały rekord jest wyświetlany jako "null"
przykładowo uid=299; tytul=Trędowata marionetka; zwraca:
  1. {"id":"299","value":null}

nie wiem czemu tak się dzieje i jak to naprawić, kodowanie bazy utf8_polish_ci, pliku utf-8 bez bom

Ten post edytował @rtur 26.09.2012, 05:55:35


--------------------
Artur
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 30.06.2025 - 05:27