DByte\DB::fetch PHP Метод

fetch() статический публичный Метод

Fetch all query result rows
static public fetch ( string $query, array $params = NULL, integer $column = NULL ) : array
$query string query string
$params array query parameters
$column integer the optional column to return
Результат array
    static function fetch($query, $params = NULL, $column = NULL)
    {
        if (!($statement = DB::query($query, $params))) {
            return;
        }
        // Return an array of records
        if ($column === NULL) {
            return $statement->fetchAll();
        }
        // Fetch a certain column from all rows
        return $statement->fetchAll(\PDO::FETCH_COLUMN, $column);
    }

Usage Example

Пример #1
0
<?php

#DB
use DByte\DB;
DB::$c = $pdo;
echo "\n\n<div class=\"panel panel-primary\">\n\t<div class=\"panel-heading\">\n\t\t<h3 class=\"panel-title\">Sensors</h3>\n\t</div>\n    <div class=\"panel-body\">\n\n\t<strong>Add sensors to the database</strong>\n\t\t<form action=\"include/add_sensors.php\" method=\"POST\" id=\"AddSensors\">\n\t\t\t<p>Recorder:<br><input type=\"text\" name=\"Recorder\" maxlength=\"100\" size=\"40\"><br>\n\t\t\tMicrophone: <br><input type=\"text\" name=\"Microphone\" maxlength=\"80\" size=\"40\"><br>\n\t\t\tNotes of the sensor: <br><input type=\"text\" name=\"Notes\" maxlength=\"255\" size=\"40\"><br>\n\t\t\t<button type=\"submit\" class=\"btn btn-primary\"> Add sensor </button>\n\t\t</form>";
#Sensors in the db:
echo "<hr noshade>";
$no_sensors = DB::column('SELECT COUNT(*) FROM `Sensors`');
if ($no_sensors == 0) {
    echo "<p>There are no sensors in the system.";
} else {
    $rows = DB::fetch('SELECT * FROM `Sensors` ORDER BY `SensorID`', array(TRUE));
    echo "<p>The system has the following " . count($rows) . " sensors:\n\t\t<table>";
    echo "<tr>\n\t\t\t<td>Sensor ID</td>\n\t\t\t<td>&nbsp;</td>\n\t\t\t<td>Recorder</td>\n\t\t\t<td>&nbsp;</td>\n\t\t\t<td>Microphone</td>\n\t\t\t<td>&nbsp;</td>\n\t\t\t<td>Notes</td>\n\t\t\t<td>&nbsp;</td>\n\t\t\t<td>Edit</td>\n\t\t</tr>\n";
    foreach ($rows as $row) {
        #	for ($i = 0; $i < $nrows; $i++) {
        #$row = mysqli_fetch_array($result);
        #extract($row);
        echo "<tr>\n\t\t\t\t<td>" . $row->SensorID . "</td>\n\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t<td>" . $row->Recorder . "</td>\n\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t<td>" . $row->Microphone . "</td>\n\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t<td>" . $row->Notes . "</td>\n\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t<td><a href=\"sensor_edit.php?SensorID=" . $row->SensorID . "\"><img src=\"images/pencil.png\"></td>\n\t\t\t</tr>\n";
    }
    echo "</table>";
}
echo "</div></div>";
All Usage Examples Of DByte\DB::fetch