Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. <?php
  2.  
  3. $host = 'localhost';
  4. $db = 'mydb';
  5. $user = 'myuser';
  6. $pass = 'mypass';
  7. $charset = 'utf8';
  8.  
  9. $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
  10. $opt = [
  11. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  12. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  13. PDO::ATTR_EMULATE_PREPARES => false,
  14. ];
  15.  
  16. $pdo = new PDO($dsn, $user, $pass, $opt);
  17.  
  18. $response = array();
  19.  
  20. $result = $pdo->query("SELECT * FROM c068t_k2_items where catid = 6");
  21. $response["items"] = array();
  22. while ($row = $result->fetch()) {
  23. //print_r($response);
  24. $product = array();
  25. $product["id"] = $row["id"];
  26. $product["title"] = $row["title"];
  27. $product["catid"] = $row["catid"];
  28. $product["published"] = $row["published"];
  29. $product["introtext"] = $row["introtext"];
  30. array_push($response["items"], $product);
  31. }
  32. $response["success"] = 1;
  33. echo json_encode($response);
  34. ?>
  35.  
  36. {
  37. "items": [
  38. {
  39. "id": 2,
  40. "title": "Заголовок",
  41. "catid": 6,
  42. "published": 1,
  43. "introtext": "Текст"
  44. },
  45. {
  46. "id": 2,
  47. "title": "Заголовок",
  48. "catid": 6,
  49. "published": 1,
  50. "introtext": "Текст"
  51. }
  52. ],
  53. "success": 1
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement