Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host = 'localhost';
- $db = 'mydb';
- $user = 'myuser';
- $pass = 'mypass';
- $charset = 'utf8';
- $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
- $opt = [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- PDO::ATTR_EMULATE_PREPARES => false,
- ];
- $pdo = new PDO($dsn, $user, $pass, $opt);
- $response = array();
- $result = $pdo->query("SELECT * FROM c068t_k2_items where catid = 6");
- $response["items"] = array();
- while ($row = $result->fetch()) {
- //print_r($response);
- $product = array();
- $product["id"] = $row["id"];
- $product["title"] = $row["title"];
- $product["catid"] = $row["catid"];
- $product["published"] = $row["published"];
- $product["introtext"] = $row["introtext"];
- array_push($response["items"], $product);
- }
- $response["success"] = 1;
- echo json_encode($response);
- ?>
- {
- "items": [
- {
- "id": 2,
- "title": "Заголовок",
- "catid": 6,
- "published": 1,
- "introtext": "Текст"
- },
- {
- "id": 2,
- "title": "Заголовок",
- "catid": 6,
- "published": 1,
- "introtext": "Текст"
- }
- ],
- "success": 1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement