/** * Tests Database->fetch() */ public function testFetch() { $obj = $this->Database->query('select 1'); $result = $this->Database->fetch($obj); if (!$result[1] == 1) { $this->fail(); } }
public static function isCurrentPanelMembersArchived() { $DB = new Database(); $sql = "SELECT UID FROM userids WHERE Responsibility != 'Member'"; $result = $DB->query($sql); while ($row = $DB->fetch($result)) { $sql = "SELECT UID FROM panelmembers WHERE UID = '" . $row['UID'] . "'"; $res = $DB->query($sql); $ret = $DB->fetch($res); if (!$ret['UID']) { return false; } } return true; }
public function buildCache() { $this->pathCache = array(); $pathModel = new Database(); $pathModel->fetch(array('table' => 'table.paths'), array('function' => array($this, 'pushPathData'))); mgExportArrayToFile(__CACHE__ . '/permalink/permalink.php', $this->pathCache, 'permalink'); }
/** *lista todos os transmissaoes cadastrados * * @return Transmissao[] */ public function listar() { $this->sql = "SELECT * FROM transmissao ORDER BY descricao"; $this->values = array(); $this->fields = array(); return parent::fetch(); }
public static function count() { $db = new Database(); $sql = "SELECT COUNT(UID) FROM userids"; $result = $db->query($sql); $row = $db->fetch($result); $db->close(); return intval($row['COUNT(UID)']) - 1; }
public static function count() { $db = new Database(); $sql = "SELECT COUNT(*) FROM events WHERE TimeNDate<date(NOW())"; $result = $db->query($sql); $row = $db->fetch($result); $db->close(); return $row['COUNT(*)']; }
/** * @covers DataBase::fetch */ public function testFetch() { $result = $this->db->fetch("SELECT * FROM test ORDER BY id"); $this->assertInternalType('array', $result); $this->assertEquals(3, $this->db->rowCount()); $this->assertEquals(2, count($result)); $this->assertEquals(array('id', 'name'), array_keys($result)); $this->assertEquals(1, $result['id']); $this->assertEquals('value 1', $result['name']); $r1 = $this->db->fetch(); $this->assertEquals(array('id', 'name'), array_keys($r1)); $this->assertEquals(2, $r1['id']); $this->assertEquals('value 2', $r1['name']); $r3 = $this->db->fetch(); // 3 linha $this->assertEquals(3, $r3['id']); $this->assertEquals('value 3', $r3['name']); $this->assertEmpty($this->db->fetch()); $r2 = $this->db->fetch("SELECT * FROM testecase WHERE id > ?", 10); $this->assertInternalType('array', $r2); $this->assertEmpty($r2); }
echo "<td class='tdheader'>"; echo "<a href='?action=row_view&table=" . urlencode($target_table) . "&sort=" . urlencode($result[$i]['name']); if (isset($_SESSION[COOKIENAME . 'sortRows'])) { $orderTag = $_SESSION[COOKIENAME . 'sortRows'] == $result[$i]['name'] && $_SESSION[COOKIENAME . 'orderRows'] == "ASC" ? "DESC" : "ASC"; } else { $orderTag = "ASC"; } echo "&order=" . $orderTag; echo "'>" . htmlencode($result[$i]['name']) . "</a>"; if (isset($_SESSION[COOKIENAME . 'sortRows']) && $_SESSION[COOKIENAME . 'sortRows'] == $result[$i]['name']) { echo $_SESSION[COOKIENAME . 'orderRows'] == "ASC" ? " <b>↑</b>" : " <b>↓</b>"; } echo "</td>"; } echo "</tr>"; for ($i = 0; $row = $db->fetch($table_result); $i++) { // -g-> $pk will always be the last columns in each row of the array because we are doing "SELECT *, PK_1, typeof(PK_1), PK2, typeof(PK_2), ... FROM ..." $pk_arr = array(); for ($col = $pkFirstCol; array_key_exists($col, $row); $col = $col + 2) { // in $col we have the type and in $col-1 the value if ($row[$col] == 'integer' || $row[$col] == 'real') { // json encode as int or float, not string $pk_arr[] = $row[$col - 1] + 0; } else { // encode as json string $pk_arr[] = $row[$col - 1]; } } $pk = json_encode($pk_arr); $tdWithClass = "<td class='td" . ($i % 2 ? "1" : "2") . "'>"; $tdWithClassLeft = "<td class='td" . ($i % 2 ? "1" : "2") . "' style='text-align:left;'>";
<?php include "config.php"; include_once "Database.php"; $db = new Database(); /* * Insert Example */ $post = array('email_user' => '*****@*****.**', 'password' => 'test'); $db->insert('users', $post); echo "Inseted Row ID is :: " . $db->InserId; echo "<br>"; /* * Select Example */ $db->select('users'); while ($r = $db->fetch()) { echo $r['email_user']; echo "<br>"; } echo "<br>"; print_r($r); echo "Total Rows : ", $db->NumRows(); echo "<br><br>"; /* * Select with where * You can use various conditions here such as like , regexp and etc... */ $db->select('users', '*', 'id = 1'); $r = $db->fetch(); print_r($r); echo "<br><br>";
require_once 'config/config.php'; require_once DIR_COMMON . 'common.php'; require_once DIR_DATABASE . "mysqli-db-obj.php"; require_once DIR_DATABASE . 'mysqli-db-obj.php'; $db = new Database(); // There are so many ways this can go wrong. Assume it is wrong first. $something_wrong = true; // To protect against CSRF attacks. $form_token = base64_encode(openssl_random_pseudo_bytes(32)); $_SESSION['form_token'] = $form_token; $post_id = $_GET['Post_ID']; // Connect to the database and retrieve the post. $stmt = "SELECT Title, Contents FROM _posts WHERE Post_ID = ?"; $types = "i"; $array_of_binds = array($post_id); $result = $db->fetch($stmt, $types, $array_of_binds); if ($result !== false) { $title = $result[0]['Title']; $contents = $result[0]['Contents']; $something_wrong = false; } // Form the site, according to whether one is logged or not $navbar = "<a class='blog-nav-item' href='index.php'>Home</a>"; $navbar .= "<a class='blog-nav-item' href='addpost.php'>Add Post</a>"; $navbar .= "<a class='blog-nav-item' href='logout.php'>Logout</a>"; // Form main content if ($something_wrong) { $main = $db->error(); } else { $main = ' <div class="col-sm-8 blog-main">
echo $row['eMail']; ?> "></div></a> </div> </div> </div> <?php } $db->close(); ?> </div> <?php $DB = new Database(); $sql = "SELECT * FROM gamingcontest"; $result = $DB->query($sql); if ($DB->fetch($result)) { ?> <div> <form method="post" action="<?php echo pure_it($_SERVER['PHP_SELF']); ?> "> <input class="button" type="submit" value="Archive" name="archive_pcp" /> </form> </div> <?php } ?> </div> </section> </main>
private function initStaticValue() { $staticModel = new Database(); $this->staticVar = array(); $staticModel->fetch(array('table' => 'table.statics'), array('function' => array($this, 'pushStaticValue'))); }
>Event Deleted!</div><?php } ?> <main> <section> <div class="container"> <div class="row"> <form method="post" action="<?php echo pure_it($_SERVER['PHP_SELF']); ?> "> <?php $DB = new Database(); $sql = "SELECT * FROM events ORDER BY TimeNDate DESC"; $result = $DB->query($sql); while ($Data = $DB->fetch($result)) { extract($Data); $date = new DateTime($TimeNDate); $TimeNDate = $date->format('h:i A, dS F, Y'); ?> <div class="columns six"> <div class="box"> <div class="title"><?php echo $Title; ?> </div> <p class="info"><span class="bold">Time & Date:</span><br><?php echo $TimeNDate; ?> </p> <p class="info"><span class="bold">Venue:</span><br><?php
$StudentID_Exist = isStudentIDExist($StudentID, 'userids_temp', $r_error); $StudentID_Exist = $StudentID_Exist ? "We already have this ID in pending request" : ""; } // Checking if File Size Exceded Limit: $ImageSize_err = validate_image_size($_FILES["Image"]["size"], $r_error); // Checking if the File is Invalid: $ImageType_err = validate_image_type($_FILES["Image"]["type"], $r_error); // Checking if the Student is from Dept. of CSE: $NonDept_err = validateStudentID($StudentID, $r_error); } if (!$r_missing && !$r_error) { // Creating the Values: $db = new Database(); $sql = "SELECT MAX(UID) FROM userids_temp"; $result = $db->query($sql); $row = $db->fetch($result); $num = intval($row['MAX(UID)']); // Inserting Values into Temporary UserIDs Table: $extension = end(explode(".", $_FILES["Image"]["name"])); $newFileName = "members/" . ++$num . "_temp." . $extension; move_uploaded_file($_FILES["Image"]["tmp_name"], $newFileName); $DateOfBirth = $_POST['YOB'] . "/" . $_POST['MOB'] . "/" . $_POST['DOB']; $data = array(); $data['StudentID'] = $StudentID; $data['Image'] = $newFileName; $data['FirstName'] = $FirstName; $data['LastName'] = $LastName; $data['dateOfBirth'] = $DateOfBirth; $data['ContactNo'] = $Phone; $data['eMail'] = $Mail; $r_success = $db->insert('userids_temp', $data);
} } //end of class // Create Connection $obj = new Database("localhost", "root", "", "student_info"); // Assign table name $tablename = "student"; // Create table query $CreateTableSql = "CREATE TABLE {$tablename}(Roll INT,Name CHAR(50),Marks DOUBLE)"; //Call Create Table $obj->CreateTable($CreateTableSql); //Associative array for insert function $InsColumnVal = array("Roll" => 4, "Name" => 'Zahan', "Marks" => 64.8); //Call insert function to insert record $obj->insert($tablename, $InsColumnVal); //Associative array for delete function $DelColumnVal = array("Roll" => 4, "Name" => 'Zahan'); //Call Delete function $obj->delete($tablename, $DelColumnVal); //Associative array to set query for update function $set = array("Roll" => 5, "Marks" => 75.3); //Associative array to condition query for update function $condition = array("Roll" => 3, "Name" => 'Hatim'); //call update function $obj->update($tablename, $set, $condition); // Fetch data from the table $show = $obj->fetch($tablename, array("Roll", "Name", "Marks")); // Show data from table echo "<pre>"; print_r($show); echo "</pre>";
public function getCount(Database $db = null) { $sql = sql::getSelect(array('COUNT(*)'), $this->tables, $this->conditions); if (null !== $db) { return $db->fetch($sql, $this->params); } return array($sql, $this->params); }
function isExist($item, $tableName, $value, &$error) { $db = new Database(); $sql = "SELECT {$item} FROM {$tableName} WHERE {$item} = '{$value}'"; $result = $db->query($sql); if (!$result) { return; } $row = $db->fetch($result); $db->close(); if ($value == $row[$item]) { $error = true; return true; } else { return false; } }
/** * select exactly one record from database * @param $db_field_names array array containing db_field_names to select for record * @param $encoded_key_string string unique identifier of record * @return array array containing exactly one record (which is an array) */ function select_record($encoded_key_string, $db_field_names = array()) { # decode key string $key_string = $this->_decode_key_string($encoded_key_string); $this->_log->trace("selecting DatabaseTable row (key_string=" . $key_string . ")"); # check if database connection is working if ($this->_check_database_connection() == FALSE) { return array(); } # check if database table exists if (!$this->_database->table_exists($this->table_name)) { $this->_handle_error("DatabaseTable does not exist in database", "ERROR_DATABASE_EXISTENCE"); return array(); } # set all db_field_names if none were provided if (count($db_field_names) == 0) { $db_field_names = $this->db_field_names; } $num_of_fields = count($db_field_names); $current_field = 0; # set all fieldnames in query $query = "SELECT "; foreach ($db_field_names as $db_field_name) { $field_type = $this->fields[$db_field_name][1]; $query .= $db_field_name; # do not add seperator after last field if ($current_field < $num_of_fields - 1) { $query .= ", "; } $current_field += 1; } # add archiver name and datetime if ($this->metadata_str[DATABASETABLE_METADATA_ENABLE_ARCHIVE] != DATABASETABLE_METADATA_FALSE) { $query .= ", " . DB_ARCHIVER_FIELD_NAME; $query .= ", " . DB_TS_ARCHIVED_FIELD_NAME; } # add creator name and datetime if ($this->metadata_str[DATABASETABLE_METADATA_ENABLE_CREATE] != DATABASETABLE_METADATA_FALSE) { $query .= ", " . DB_CREATOR_FIELD_NAME; $query .= ", " . DB_TS_CREATED_FIELD_NAME; } # add modifier name and datetime if ($this->metadata_str[DATABASETABLE_METADATA_ENABLE_MODIFY] != DATABASETABLE_METADATA_FALSE) { $query .= ", " . DB_MODIFIER_FIELD_NAME; $query .= ", " . DB_TS_MODIFIED_FIELD_NAME; } $query .= " FROM " . $this->table_name . " WHERE " . $key_string; $result = $this->_database->query($query); if ($result != FALSE) { $row = $this->_database->fetch($result); if (count($row) > 0) { # decode text field foreach ($db_field_names as $db_field_name) { $field_type = $this->fields[$db_field_name][1]; if (stristr($field_type, "TEXT")) { $row[$db_field_name] = html_entity_decode($row[$db_field_name], ENT_QUOTES); } } $this->_log->trace("selected DatabaseTable row"); return $row; } else { $this->_log->warn("fetching from database yielded no results"); return array(); } } else { $this->_handle_error("could not read DatabaseTable row from table", "ERROR_DATABASE_PROBLEM"); return array(); } }
<th>#</th> <th>Class Name</th> <th>Section 1</th> <th>Section 2</th> <th>Section 3</th> <th>Manage</th> </tr> </thead> <tbody> <?php require_once '../func/functions.php'; $oDb = new Database(); $query = $oDb->query("SELECT * from class order by class"); $sl = 1; while ($result = $oDb->fetch($query)) { ?> <tr> <td><?php echo $sl++; ?> </td> <td><?php echo $result['class']; ?> </td> <td><?php echo $result['c_sec1']; ?> </td> <td><?php
<?php require 'controler/init.php'; require 'controler/user_controler.php'; //session_start(); if (isset($_GET['product_nb'])) { var_dump($_GET['product_nb']); $conn = new Database(); $sql_product = "SELECT * FROM product WHERE id = {$_GET['product_nb']}"; $conn->query($sql_product); $conn->execute(); $row = $conn->fetch(); // Verifier si le produit existe if ($row) { $conn = null; // Afficher le contenu de la page si le contenu existe $template = new Template('template/product.tmpl.php'); echo $template; } else { var_dump($_GET['product_nb']); // Rediriger vers une page d'erreur si le produit n'existe pas //header("Location: index.php?error=2"); } } else { header("index.php"); exit; }
function fatal($str) { global $update_string; echo "<br><strong><font color=\"red\">" . $update_string . " failed</font><br>"; exit(" -> " . $str . "</strong><br>"); } # opening message echo "<strong>starting " . $update_string . "</strong><br><br>\n"; $updated_lists = 0; $list_ids_array = array(); $json = new Services_JSON(); echo "updating lists<br>"; $query = "SELECT _id, _title, _description, _definition FROM " . LISTTABLEDESCRIPTION_TABLE_NAME; $query_result = $database->query($query); if ($query_result != FALSE) { while ($row = $database->fetch($query_result)) { $list_name = $row[1]; $table_name = LISTTABLE_TABLE_NAME_PREFIX . strtolower(str_replace(" ", "_", $row[1])); $description = html_entity_decode(html_entity_decode($row[2], ENT_QUOTES), ENT_QUOTES); $definition = (array) $json->decode(html_entity_decode(html_entity_decode($row[3], ENT_QUOTES), ENT_QUOTES)); echo "updating list: <strong>" . $list_name . "</strong> (" . $table_name . ")<br>\n"; $field_names = array_keys($definition); echo " updating list description<br>\n"; $previous_field_name = ""; foreach ($field_names as $field_name) { $field_definition = $definition[$field_name]; $field_type = $field_definition[0]; # echo " found field <strong>".$field_name."</strong> of field type ".$field_type."<br>\n"; # update auto update field if ($field_type == "LABEL_DEFINITION_AUTO_DATE") { $new_field_definition = array();
<div class="student"> <h1 class="text-uppercase text-center sname">school name</h1> <p class="text-center">Address</p> <div class="show_res"> <div class="col-sm-6"> <div class="row text-center"> <h2>Search Result</h2> <form action="inc/options.php" method="post"> <input type="hidden" name="OP" value="SRSRES"/> <div class="col-sm-8 col-sm-offset-2"> <div class="row"> <select name="class" id="" class="form-control"> <option value="" default>Select Class</option> <?php $qr = $oDb->query("select * from class"); while ($result = $oDb->fetch($qr)) { ?> <option value="<?php echo $result['class']; ?> "><?php echo $result['class']; ?> </option> <?php } ?> </select> </div> <div class="row"> <select name="exam" id="" class="form-control">
public function buildCache() { $this->pathCache = array(); $pathModel = new Database(); $pathModel->fetch(array('table' => 'table.paths'), array('function' => array($this, 'pushPathData'))); foreach ($this->pathCache as $key => $val) { mgExportArrayToFile(__CACHE__ . '/action/' . $key . '.php', $val, 'pathConfig', true); } }
$condition_stmt = substr($condition_stmt, 0, -4); // Remove the final AND $stmt .= $condition_stmt; } $stmt .= " ORDER BY Time DESC LIMIT 5"; $start = 0; if (isset($query_array['start'])) { $start = $query_array['start']; $stmt .= ' OFFSET ?'; $types .= 'i'; $array_of_binds[] = $start; } if ($types === '') { $result = $db->simple_fetch($stmt); } else { $result = $db->fetch($stmt, $types, $array_of_binds); } // Form the navbar accordingly if ($logged) { $navbar = "<a class='blog-nav-item active' href='index.php'>Home</a>"; $navbar .= "<a class='blog-nav-item' href='addpost.php'>Add Post</a>"; $navbar .= "<a class='blog-nav-item' href='logout.php'>Logout</a>"; } else { $navbar = "<a class='blog-nav-item active' href='index.php'>Home</a>"; $navbar .= "<a class='blog-nav-item' href='login.php'>Login</a>"; $navbar .= "<a class='blog-nav-item' href='register.php'>Register</a>"; } // Form the main contents $main = ""; // Display heading of user's posts, if requested $username_stmt = "SELECT username FROM _users\nWHERE ID = ?;";
public static function findById($id) { $sql = "SELECT * FROM users WHERE id = ?"; $user = Database::fetch($sql, [$id]); return new User($user->id, $user->name, $user->first_name, $user->password, $user->email); }
<![endif]--> </head> <body> <?php require_once 'adminnav.php'; ?> <main> <section> <div class="container"> <div class="row"> <?php $db = new Database(); $sql = "SELECT UID FROM userids\n WHERE userids.UID BETWEEN '{$from}' AND '{$to}'"; $result = $db->query($sql); while ($R = $db->fetch($result)) { if ($R['UID'] == "UIC-000") { continue; } $Member = new Member($R['UID']); ?> <div class="columns two"> <div class="person"> <div class="img" style="background: url('<?php echo $Member->getImage(); ?> ') no-repeat; background-size: 100% 100%;"></div> <p class="info italic"><?php echo $Member->getFullName(); ?> </p>
<?php require 'database.php'; Database::setUsername('root'); Database::setPassword(''); Database::setHostname('localhost'); Database::setDatabase('test'); Database::setDBLink('default'); Database::connect(); $rowSingleAccount1 = Database::fetch("SELECT * FROM account WHERE id = :id", [['id', 1, 'int']]); $rowSingleAccount2 = Database::fetch("SELECT * FROM account WHERE id = :id", [['id', 1, 'int']]); echo '<pre>'; print_r($rowSingleAccount1); print_r($rowSingleAccount2); echo '</pre>'; $rowMultiAccount = Database::fetchAll("SELECT * FROM account"); echo '<pre>'; print_r($rowMultiAccount); echo '</pre>'; // $fullname = 'Peter'; // Database::exec("INSERT INTO account(fullname) // VALUES(:fullname)", [ // ['fullname', $fullname, 'str'] // ]); echo '<hr />'; echo '<pre>'; print_r(Database::getStatistics()); echo '</pre>';
"> <div id="n" class="np icon32x32 i7"><p>Next</p></div></a> <?php } ?> </div> <?php } ?> <div class="row"> <?php $DB = new Database(); foreach (PanelMember::$Designations as $key => $value) { if (isset($_GET['from']) && isset($_GET['to'])) { $sql = "SELECT UID FROM panelmembers WHERE Responsibility = '" . $key . "' AND session_from = '" . pure_it($_GET['from']) . "' AND session_to = '" . pure_it($_GET['to']) . "'"; $result = $DB->query($sql); $row = $DB->fetch($result); $PanelMember = new Member($row['UID']); } elseif (isset($_GET['group'])) { $sql = "SELECT UID FROM panelmembers WHERE Responsibility = '" . $key . "' AND session_group = '" . pure_it($_GET['group']) . "'"; $result = $DB->query($sql); $row = $DB->fetch($result); $PanelMember = new Member($row['UID']); } else { $PanelMember = new PanelMember($key); } ?> <div class="columns three"> <div class="person"> <div class="img" style="background: url('<?php echo $PanelMember->getImage(); ?>
<thead> <tr> <th>#</th> <th>User's Name</th> <th>Username</th> <th>Designation</th> <th>Email</th> <th>Role</th> <th>Manage</th> </tr> </thead> <tbody> <?php $qr = $oDb->query("select * from user"); $sl = 1; while ($data = $oDb->fetch($qr)) { ?> <tr> <td><?php echo $sl++; ?> </td> <td><?php echo $data['name']; ?> </td> <td><?php echo $data['uname']; ?> </td> <td><?php
?> </th> <th><?php echo _("Module"); ?> </th> <th><?php echo _("Résultat"); ?> </th> </tr> <TR> <?php $max = $cn->count(); for ($i = 0; $i < $max; $i++) { $r = $cn->fetch($i); ?> <td> <?php echo h($r['ac_user']); ?> </td> <td> <?php echo $r['fmt_date']; ?> </td> <td> <?php