fetch() static public method

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
return array
Esempio n. 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>";
Esempio n. 2
0
use DByte\DB;
DB::$c = $pdo;
#If user is not logged in, add check for QF
if ($pumilio_loggedin == FALSE) {
    $qf_check = "AND `Sounds`.`QualityFlagID`>={$default_qf}";
} else {
    $qf_check = "";
}
echo "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<title>{$app_custom_name}</title>";
require "include/get_css3.php";
require "include/get_jqueryui.php";
####################################################3
$use_googlemaps = FALSE;
$use_leaflet = TRUE;
#Get points from the database
$results_map = DB::fetch('SELECT `Sites`.`SiteID`, `Sites`.`SiteLat`, `Sites`.`SiteLon`, `Sites`.`SiteName` FROM `Sites`, `Sounds` WHERE `Sites`.`SiteLat` IS NOT NULL AND `Sites`.`SiteLon` IS NOT NULL AND `Sites`.`SiteID`=`Sounds`.`SiteID` AND `Sounds`.`SoundStatus` != 9 GROUP BY `Sites`.`SiteID`, `Sites`.`SiteLat`, `Sites`.`SiteLon`, `Sites`.`SiteName`');
$no_results_map = count($results_map);
####################################################3
require "include/index_map_head.php";
echo "\n\t<!-- Form validation from http://bassistance.de/jquery-plugins/jquery-plugin-validation/ -->\n\t<script src=\"js/jquery.validate.js\" type=\"text/javascript\"></script>\n\n\t<script type=\"text/javascript\">\n\t\$().ready(function() {\n\t\t// validate signup form on keyup and submit\n\t\t\$(\"#AddSample1\").validate({\n\t\t\trules: {\n\t\t\t\tsamplesize: {\n\t\t\t\t\trequired: true,\n\t\t\t\t\tnumber: true\n\t\t\t\t},\n\t\t\t\tsamplename: {\n\t\t\t\t\trequired: true\n\t\t\t\t}\n\t\t\t},\n\t\t\tmessages: {\n\t\t\t\tsamplesize: \"Please enter the size of the sample set you want to create\",\n\t\t\t\tsamplenaMe: \"Please enter a name for this sample set\"\n\t\t\t}\n\t\t\t});\n\t\t});\n\t</script>\n\t\n\t<script type=\"text/javascript\">\n\t\$().ready(function() {\n\t\t// validate signup form on keyup and submit\n\t\t\$(\"#AddSample2\").validate({\n\t\t\trules: {\n\t\t\t\tsamplesize: {\n\t\t\t\t\trequired: true,\n\t\t\t\t\tnumber: true\n\t\t\t\t},\n\t\t\t\tsamplename: {\n\t\t\t\t\trequired: true\n\t\t\t\t}\n\t\t\t},\n\t\t\tmessages: {\n\t\t\t\tsamplesize: \"Please enter the size of the sample set you want to create\",\n\t\t\t\tsamplename: \"Please enter a name for this sample set\"\n\t\t\t}\n\t\t\t});\n\t\t});\n\t</script>\n\t\n\t<script type=\"text/javascript\">\n\t\$().ready(function() {\n\t\t// validate signup form on keyup and submit\n\t\t\$(\"#AddSample3\").validate({\n\t\t\trules: {\n\t\t\t\tsample_percent: {\n\t\t\t\t\trequired: true,\n\t\t\t\t\tnumber: true\n\t\t\t\t},\n\t\t\t\tsamplename: {\n\t\t\t\t\trequired: true\n\t\t\t\t}\n\t\t\t},\n\t\t\tmessages: {\n\t\t\t\tsamplesize: \"Please enter the percent size of the sample set you want to create\",\n\t\t\t\tsamplename: \"Please enter a name for this sample set\"\n\t\t\t}\n\t\t\t});\n\t\t});\n\t</script>\n\n\t<script type=\"text/javascript\">\n\t\$().ready(function() {\n\t\t// validate signup form on keyup and submit\n\t\t\$(\"#AddSample4\").validate({\n\t\t\trules: {\n\t\t\t\tsample_percent: {\n\t\t\t\t\trequired: true,\n\t\t\t\t\tnumber: true\n\t\t\t\t},\n\t\t\t\tsamplename: {\n\t\t\t\t\trequired: true\n\t\t\t\t}\n\t\t\t},\n\t\t\tmessages: {\n\t\t\t\tsamplesize: \"Please enter the percent size of the sample set you want to create\",\n\t\t\t\tsamplename: \"Please enter a name for this sample set\"\n\t\t\t}\n\t\t\t});\n\t\t});\n\t</script>\n\t\n\t<script type=\"text/javascript\">\n\t\$().ready(function() {\n\t\t// validate signup form on keyup and submit\n\t\t\$(\"#AddSample5\").validate({\n\t\t\trules: {\n\t\t\t\tsample_percent: {\n\t\t\t\t\trequired: true,\n\t\t\t\t\tnumber: true\n\t\t\t\t},\n\t\t\t\tsamplename: {\n\t\t\t\t\trequired: true\n\t\t\t\t}\n\t\t\t},\n\t\t\tmessages: {\n\t\t\t\tsamplesize: \"Please enter the percent size of the sample set you want to create\",\n\t\t\t\tsamplename: \"Please enter a name for this sample set\"\n\t\t\t}\n\t\t\t});\n\t\t});\n\t</script>\n\t\t\n\t<style type=\"text/css\">\n\t#fileForm label.error {\n\t\tmargin-left: 10px;\n\t\twidth: auto;\n\t\tdisplay: inline;\n\t}\n\t</style>";
$DateLow = DB::column('SELECT DATE_FORMAT(`Date`,"%Y, %c-1, %e") FROM `Sounds` WHERE `SoundStatus`!=9 ' . $qf_check . ' ORDER BY `Date` LIMIT 1');
$DateHigh = DB::column('SELECT DATE_FORMAT(`Date`, "%Y, %c-1, %e") FROM `Sounds` WHERE `SoundStatus`!=9 ' . $qf_check . ' ORDER BY `Date` DESC LIMIT 1');
$DateLow1 = DB::column('SELECT DATE_FORMAT(`Date`, "%d-%b-%Y") FROM `Sounds` WHERE `SoundStatus`!=9 ' . $qf_check . ' ORDER BY `Date` LIMIT 1');
$DateHigh1 = DB::column('SELECT DATE_FORMAT(`Date`, "%d-%b-%Y") FROM `Sounds` WHERE `SoundStatus`!=9 ' . $qf_check . ' ORDER BY `Date` DESC LIMIT 1');
#from http://jsbin.com/orora3/75/
echo "\t\n\t<script type=\"text/javascript\">\n\t\$(function() {\n\t\tvar dates = \$( \"#startDate, #endDate\" ).datepicker({\n\t\t\tminDate: new Date({$DateLow}),\n\t\t\tmaxDate: new Date({$DateHigh}),\n\t\t\tnumberOfMonths: 3,\n\t\t\tchangeYear: true,\n\t\t\tdateFormat: 'dd-MM-yy',\n\t\t\tonSelect: function( selectedDate ) {\n\t\t\t\tvar option = this.id == \"startDate\" ? \"minDate\" : \"maxDate\",\n\t\t\t\tinstance = \$( this ).data( \"datepicker\" ),\n\t\t\t\tdate = \$.datepicker.parseDate(\n\t\t\t\t\tinstance.settings.dateFormat ||\n\t\t\t\t\t\$.datepicker._defaults.dateFormat,\n\t\t\t\t\tselectedDate, instance.settings );\n\t\t\t\tdates.not( this ).datepicker( \"option\", option, date );\n\t\t\t}\n\t\t});\n\t});\n\n\t</script>\n\t";
#Duration slider
#Get min and max
$DurationLow = floor(DB::column('SELECT DISTINCT `Duration` FROM `Sounds` WHERE `Duration` IS NOT NULL AND `SoundStatus`!=9 ' . $qf_check . ' ORDER BY `Duration` LIMIT 1'));
$DurationHigh = ceil(DB::column('SELECT DISTINCT `Duration` FROM `Sounds` WHERE `Duration` IS NOT NULL AND `SoundStatus`!=9 ' . $qf_check . ' ORDER BY `Duration` DESC LIMIT 1'));
echo "<script type=\"text/javascript\">\n\t\t\$(function() {\n\t\t\t\$( \"#durationslider\" ).slider({\n\t\t\trange: true,\n\t\t\t\tmin: {$DurationLow},\n\t\t\t\tmax: {$DurationHigh},\n\t\t\t\tvalues: [ {$DurationLow}, {$DurationHigh} ],\n\t\t\t\tslide: function( event, ui ) {\n\t\t\t\t\t\$( \"#startDuration\" ).val( \$( \"#durationslider\" ).slider( \"values\", 0 ));\n\t\t\t\t\t\$( \"#endDuration\" ).val( \$( \"#durationslider\" ).slider( \"values\", 1 ));\n\t\t\t\t}\n\t\t\t});\n\t\t\t\$( \"#startDuration\" ).val( \$( \"#durationslider\" ).slider( \"values\", 0 ));\n\t\t\t\$( \"#endDuration\" ).val( \$( \"#durationslider\" ).slider( \"values\", 1 ));\n\t\t\t});\n\t\t</script>";
Esempio n. 3
0
// Oops! We got Bob's info wrong! Lets fix it!
$user = array('username' => 'Bob', 'email' => '*****@*****.**');
$result = DB::update('users', $user, 3);
var_dump($result);
// Our moderators say that the "Troll" user needs to be deleted!
$result = DB::query('DELETE FROM users WHERE username = ?', array('Troll'));
var_dump($result);
/*
 * Select Queries
 */
// Count all the users
$result = DB::column('SELECT COUNT(*) FROM `users`');
var_dump('Total users: ' . $result);
br();
// Get user number 2 (John)
$result = DB::row('SELECT * FROM `users` WHERE id = ?', array(3));
var_dump($result);
br();
// Fetch all the users!
$result = DB::fetch('SELECT * FROM `users`');
var_dump($result);
br();
// Fetch users from "example.com"
$result = DB::fetch('SELECT * FROM `users` WHERE email LIKE ?', array('%example.com'));
var_dump($result);
br();
/*
 * Results
 */
print count(DB::$q) . " Queries Run:\n";
print_r(DB::$q);