HEX
Server: Apache
System: Linux b:u:marcbase:1 3.10.0-1160.31.1.el7.x86_64 #1 SMP Thu Jun 10 13:32:12 UTC 2021 x86_64
User: apache (92344)
PHP: 7.0.18
Disabled: apache_get_modules, apache_get_version, apache_reset_timeout, apache_getenv, apache_note, apache_setenv
Upload Files
File: /var/www/html/marcbase.com.br/web/mybringback/comments.php
<?php



/*

Our "config.inc.php" file connects to database every time we include or require

it within a php script.  Since we want this script to add a new user to our db,

we will be talking with our database, and therefore,

let's require the connection to happen:

*/

require("config.inc.php");



//initial query

$query = "Select * FROM comments";



//execute query

try {

    $stmt   = $db->prepare($query);

    $result = $stmt->execute($query_params);

}

catch (PDOException $ex) {

    $response["success"] = 0;

    $response["message"] = "Database Error!";

    die(json_encode($response));

}



// Finally, we can retrieve all of the found rows into an array using fetchAll 

$rows = $stmt->fetchAll();





if ($rows) {

    $response["success"] = 1;

    $response["message"] = "Post Available!";

    $response["posts"]   = array();

    

    foreach ($rows as $row) {

        $post             = array();

		$post["post_id"]  = $row["post_id"];

        $post["username"] = $row["username"];

        $post["title"]    = $row["title"];

        $post["message"]  = $row["message"];

        

        

        //update our repsonse JSON data

        array_push($response["posts"], $post);

    }

    

    // echoing JSON response

    echo json_encode($response);

    

    

} else {

    $response["success"] = 0;

    $response["message"] = "No Post Available!";

    die(json_encode($response));

}



?>