Exemplo n.º 1
0
/**
 * function getGardens()
 * 
 * preconditions: a file of the form given in DemoCreds.php that contains
 *                the credentials that will be used to access the database.
 *                This is not secure -- just for demo purposes.
 * 
 * arguments: none
 *
 * action: retrieves all of the rows from table RectGardens and returns
 *         them in toto in the gardens property of the returned object.  
 *
 * return An object that has the following fields:
 *     connect_error: error returned from mysqli_connect but only if an error 
 *                    occured.  null otherwise
 *     success: a boolean indicating if the call was successful (true) or not
 *     gardens: an array of rows as arrays of columns
 *     querystring: the query string that was executed
 *     credentials: is this a bad idea or what?
 * 
 * postconditions
 */
function getGardens()
{
    $dbConn = mysqli_connect(demoServer(), demoUsername(), demoPassword(), demoDB());
    $query = "SELECT * FROM RectGarden";
    $result = $dbConn->query($query);
    if ($dbConn->connect_error) {
        $return->connect_error = "Connection failed: " . $dbConn->connect_error;
        $return->success = false;
        return json_encode($return);
    }
    $gardens = array();
    if ($result) {
        while ($row = $result->fetch_array()) {
            $allColumns = array();
            for ($i = 0; $i < 7; $i++) {
                array_push($allColumns, $row[$i]);
            }
            array_push($gardens, $allColumns);
        }
    }
    $return = new stdClass();
    $return->success = true;
    $return->gardens = $gardens;
    $return->querystring = $query;
    return json_encode($return);
}
Exemplo n.º 2
0
function getPlayer()
{
    $dbConn = mysqli_connect(demoServer(), demoUsername(), demoPassword(), demoDB());
    $query = "SELECT * FROM player_table";
    $result = $dbConn->query($query);
    if ($dbConn->connect_error) {
        $return = "";
        $return->connect_error = "Connection failed: " . $dbConn->connect_error;
        $return->success = false;
        return json_encode($return);
    }
    $player = array();
    if ($result) {
        while ($row = $result->fetch_array()) {
            $allColumns = array();
            for ($i = 0; $i < 6; $i++) {
                array_push($allColumns, $row[$i]);
            }
            array_push($player, $allColumns);
        }
    }
    $return = new StdClass();
    $return->success = true;
    $return->player = $player;
    $return->querystring = $query;
    $return->credentials = demoUsername() . demoPassword() . demoDB() . " on " . demoServer();
    return json_encode($return);
}