public static function getRoles($names = null, $enable = null) { //подготавливаем запрос на выборку Database::DB()->reset(); Database::DB()->select(self::$roles_table, "name,enable"); //в зависимости от $names добавляем условие if (isset($names)) { if (empty($names)) { return array(); } if (is_array($names)) { Database::DB()->where("name", $names, "IN"); } else { Database::DB()->where("name", $names, "LIKE"); } } //в зависимости от $enable добавляем условие if (isset($enable)) { Database::DB()->sqlAND(); Database::DB()->where("enable", $enable, '='); } //выполняем запрос Database::DB()->exec(); //echo Database::DB()->lastQuery().'<br/>'; //копируем результат в массив $roles = array(); while ($row = Database::getRow()) { array_push($roles, $row); } //и возвращаем результат return $roles; }
public function testGetRowWrongParam() { $db = new Database(); $get_logs_stmt = $db->prepare('SELECT id FROM Users'); $get_logs_stmt->execute(); $results = $db->getRow($db); $this->assertTrue(empty($results)); }
public function __construct($id = null, $id_lang = null) { $this->id_lang = $id_lang; foreach (static::$fields as $field) { $this->values[$field] = null; } if (is_numeric($this->id_lang)) { if ($this->id_lang) { foreach (static::$fieldsLang as $field) { $this->values_lang[$field] = null; } } else { $langs = App::getLangs(); foreach (static::$fieldsLang as $field) { $this->values_lang[$field] = array(); foreach ($langs as $lang) { $this->values_lang[$field][$lang->getId()] = null; } } } } if ($id) { if (is_numeric($this->id_lang) && static::hasLang()) { if ($this->id_lang) { $row = Database::getRow("\n SELECT `t`.*, `l`.`" . implode('`, `l`.`', static::$fieldsLang) . "`\n FROM `" . static::TABLE . "` AS `t`\n LEFT JOIN `" . static::TABLE . "_lang` AS `l` ON `l`.`id_object` = {$id} AND `l`.`id_lang` = {$id_lang}\n WHERE `t`.`id` = {$id}\n "); $this->id = $row['id']; foreach (static::$fields as $field) { $this->values[$field] = $row[$field]; } foreach (static::$fieldsLang as $field) { $this->values_lang[$field] = $row[$field]; } } else { $row = Database::getRow("\n SELECT *\n FROM `" . static::TABLE . "`\n WHERE `id` = {$id}\n "); $this->id = $row['id']; foreach (static::$fields as $field) { $this->values[$field] = $row[$field]; } $rows = Database::getTable("\n SELECT `l`.*\n FROM `" . static::TABLE . "_lang` AS `l`\n LEFT JOIN `lang` AS `ll` ON `l`.`id_lang` = `ll`.`id`\n WHERE `l`.`id_object` = {$this->id} AND `ll`.`active` = 1\n "); foreach ($rows as $row) { $lang = $row['id_lang']; foreach (static::$fieldsLang as $field) { $this->values_lang[$field][$lang] = $row[$field]; } } } } else { $row = Database::getRow("\n SELECT *\n FROM `" . static::TABLE . "`\n WHERE `id` = {$id}\n "); $this->id = $row['id']; foreach (static::$fields as $field) { $this->values[$field] = $row[$field]; } } } }
protected function build(PageBody &$body, SubMenu &$submenu) { //var_dump($_SESSION['db']); $subPage = isset($_GET['subpage']) ? $_GET['subpage'] : ''; if (isset($_GET['event'])) { $this->event = Database::getRow('Event', $_GET['event']); $this->event->id = $_GET['event']; // for testing $this->pageName = $this->event->name; //var_dump($this->event); } if ($this->event == null) { $body->addToTop(new Message("No Event", Message::DANGER)); } $submenu->addLink("Event Details", "?page=Event&event=" . $this->event->id, $subPage == ''); $submenu->addLink("Update Event", "?page=Event&event=" . $this->event->id . "&subpage=update", $subPage == 'update'); $submenu->addSplitter(); $submenu->addLink("Send Email Invitation", "?page=Event&event=" . $this->event->id . "&subpage=send", $subPage == 'send'); $submenu->addLink("Add VIP Participant", "#"); $submenu->addSplitter(); $submenu->addLink("Show All Participants", "#", false, false, 100); $submenu->addLink("Show Missing Participants", "#", false, false, 90); $submenu->addLink("Show Event Attendances", "#", false, false, 10); $submenu->addSplitter(); $submenu->addLink("Build Schedule", "#"); $submenu->addLink("Send Schedule", "#"); $submenu->addLink("Start Timer", "#"); $submenu->addSplitter(); $submenu->addDangerLink("Delete Event", "#"); $body->addToTop(new CustomHTML("\n <div class='page-header'>\n <h1> " . $this->event->name . " <small>" . $this->event->address . "</small></h1>\n </div>\n ")); if ($subPage == '') { $body->addToCenter(new CustomHTML("\n <dl class='dl-horizontal' style='font-size:18px'>\n <dt>Name</dt>\n <dd>" . $this->event->name . "</dd>\n <dt>Address</dt>\n <dd>" . $this->event->address . "</dd>\n </dl>\n ")); } else { if ($subPage == 'update') { $form = new Form("Event"); $form->addInput(Input::textInput("eventName", "Event Name", $this->event->name)); $form->addInput(Input::textareaInput("eventAddress", "Event Address", $this->event->address)); $body->addToCenter($form); } else { if ($subPage == 'send') { $form = new Form("Event"); $form->addInput(Input::tokenInput("emails", "Send To:")); $form->addInput(Input::textInput("subject", "Subject", "Invitation to " . $this->event->name)); $form->addInput(Input::textareaInput("message", "Message")); $body->addToCenter($form); } } } // $table = new HtmlTable(); // $table->addRow(["Name", $this->event->name]); // $table->addRow(["Address", $this->event->address]); // // $body->addToCenter($table); }
public static function getByEmail($email) { $row = Database::getRow("\n SELECT *\n FROM `user`\n WHERE `email` = '{$email}'\n "); if (!empty($row)) { $customer = new UserModel(); $customer->id = $row['id']; $customer->name = $row['name']; $customer->email = $email; $customer->password = $row['password']; return $customer; } return null; }
public function __construct($id) { $row = Database::getRow('User', 'id="' . $id . '"'); if (!$row) { die('User ' . $id . " does not exist.\n"); } $this->id = $id; $this->name = $row['name']; $this->username = $row['username']; $this->spirit = $row['spirit']; $this->quests = array('LRC' => new LRC_QuestLine($id)); $this->badges = array('SeaPup' => new SeaPup_Badge($id)); }
/** * Player ID beállítása * @author vitozy */ public function setUserID() { if ($this->isLoggedIn() == false) { $this->userid = 0; $_SESSION['userid'] = 0; } else { $username = $_SESSION['name']; $db = new Database(); $user = $db->getRow("SELECT * FROM users WHERE name = '{$username}'"); $db->close(); $this->userid = $user['userid']; $_SESSION['userid'] = $user['userid']; } }
public function load($keyload) { $conditions = array(); if (is_array($keyload)) { foreach ($keyload as $k => $v) { $conditions[] = "{$k}='{$v}'"; } } else { $t = $this->index(); $conditions[] = $t[0] . "='{$keyload}'"; } $result = Database::getRow("SELECT * FROM " . CONFIG_DB_PREFIX . $this->tableName() . " WHERE " . implode(" AND ", $conditions)); if ($result !== false) { $this->_data = $result; return true; } return false; }
protected static function init() { parent::init(); /* * Если текущий запрос не ajax * Происходит привязка глобальных данных для левого меню */ if (!App::isAjax()) { // Привязка списка категорий $collection = new Collection('Category', App::currentLang()->getId()); $collection->where("`active` = 1"); static::templateGlobal('aside_categories', $collection->items()); // Привязка списка производителей $collection = new Collection('Brand', App::currentLang()->getId()); $collection->where("`active` = 1"); static::templateGlobal('aside_brands', $collection->items()); // Привязка данных для фильтра цен static::templateGlobal('filter_price', Database::getRow("\n SELECT\n MIN(`price`) AS `min`,\n MAX(`price`) AS `max`\n FROM `product`\n WHERE `active` = 1\n ")); } }
static function findPage($name) { Database::DB()->select('pages')->where('name', $name)->exec(); return Database::getRow(); }
/** * Checks if the passed string is unique in the Users table * * @static * @param string $username * @return boolean */ public static function isUsernameUnique($username) { $db = new Database(); $get_username_stmt = $db->prepare('SELECT id FROM Users WHERE username = ?'); $get_username_stmt->bind_param('s', $username); $get_username_stmt->execute(); if ($row = $db->getRow($get_username_stmt)) { return true; } return false; }
public function __construct($id) { $row_c = Database::getRow('LRC', 'label="LRC_Quest"'); $row_v = Database::getQuestRow('LRC_Quest', '' . $id, 'active, complete, visible', '1, 0, 1'); parent::__construct(array('name' => $row_c['name'], 'active' => $row_v['active'], 'complete' => $row_v['complete'], 'visible' => $row_v['visible'], 'objective' => $row_c['objective'], 'reward' => $row_c['reward'], 'quests' => array(0 => new LRC_Visit($id), 1 => new LRC_GetPlanner($id), 2 => new LRC_SayingOnWall($id), 3 => new LRC_VisitWritingCenter($id), 4 => new LRC_VisitLRCMathLab($id), 5 => new LRC_TypesOfCoaching($id), 6 => new LRC_Appointment($id), 7 => new LRC_TopicsOfACC($id), 8 => new LRC_WednesdayWorkshop($id)))); }
function getAll($where = null, $order = null, $order_by = null) { if (!is_null($this->db)) { $db = $this->db; } else { $db = new Database("db13310_notes"); } $sql = "SELECT id,found_date,content FROM notes "; if (!is_null($where)) { $where_clause = array(); foreach ($where as $field => $val) { $where_clause[] = "(" . $field . "='" . $val . "') "; } if (count($where_clause) > 0) { $sql .= "WHERE " . implode($where_clause, " AND "); } } if (!is_null($order)) { $sql .= "ORDER BY " . $order . " "; $sql .= !is_null($order_by) ? $order_by : "ASC"; } $query = $db->query($sql); $results = array(); while ($row = $db->getRow($query)) { $results[] = $row; } return $results; }
<?php require_once 'Database.php'; $operation = $_GET['operation']; $database = new Database('localhost', 'default', 'default', 'user'); session_start(); if ($operation == 'login') { $username = $_GET['username']; $password = $_GET['password']; $database->select('users', 'name', 'username=\'' . $username . '\' and password=sha1(\'' . $password . '\')'); if (!$database->hasRow()) { echo 'No user'; } else { $userInformation = $database->getRow(); echo $userInformation['name']; $_SESSION['logged-in'] = true; $_SESSION['name'] = $userInformation['name']; } } else { if ($operation == 'logout') { unset($_SESSION['logged-in']); unset($_SESSION['name']); session_destroy(); } }
protected static function actionDownImage() { $image = Database::getRow("\n SELECT *\n FROM `product_image`\n WHERE `id` = {$_GET['id']}\n "); Database::query("\n UPDATE `product_image`\n SET `position` = `position` - 1\n WHERE `id_product` = {$image['id_product']} AND `position` = {$image['position']} + 1\n "); Database::query("\n UPDATE `product_image`\n SET `position` = `position` + 1\n WHERE `id` = {$image['id']}\n "); self::redirect(App::getLink('AdminProducts', array('action' => 'edit', 'id' => $image['id_product']))); }
<html> <head> <meta charset="UTF-8"> <title>Todo List</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="js/main.js"></script> <link rel="stylesheet" type="text/css" href="css/main.css"> </head> <body> <?php include 'include/include_fns.php'; $db = new Database(); // Display the users name $db->query("SELECT uid, name FROM account LIMIT 1"); $db->execute(); $row = $db->getRow(); echo "<div id='nameheader'>"; echo "<h2>" . $row['name'] . "'s todo list</h2>"; echo "</div>"; $uid = $row['uid']; // Get all the Todo Items $items = json_decode(Todo::getAllItems($uid)); ?> <div id='table-div'> <table id='table'> <tr><th>Completed</th><th>Todo Item</th><th>Delete Item</th></tr> <?php foreach ($items as $id => $item) { $checked = ""; if ($item[1] == 1) { $checked = "checked";
function getLocations() { $db = new Database( "db13310_notes" ); $sql = "SELECT * FROM location "; $where = array(); if(!is_null($where)){ $where_clause = array(); foreach($where as $field=>$val){ $where_clause[]="(".$field."='".$val."') "; } if(count($where_clause)>0){ $sql .= "WHERE ".implode($where_clause," AND "); } } if(is_null($order)) $order = "city"; if(!is_null($order)){ $sql .= "ORDER BY ".$order." "; $sql .= !is_null($order_by) ? $order_by : "ASC"; } $query = $db->query($sql); while($row = $db->getRow($query)){ $item = array( 'id' => $row['id'], 'city' => $row['city'], 'state' => $row['state'], 'country' => $row['country'] ); $items[] = $item; } return $items; }
<?php /* ** DB Class ** @Author Round */ header("Content-type: text/html; charset=utf-8"); //编码 // 导入数据库配置文件,后续可通过传参实现多个连接 require_once "./db.cfg.php"; // 数据库类 require_once "./database.core.php"; // 新建数据库对象 $dbConfig $db = new Database($dbConfig); echo "<pre>"; // 一位数组 $sqlOne = 'select * from jcc_admin where id = 5'; $row = $db->getRow($sqlOne); var_dump($row); // 二维数组 $sqlList = 'select * from jcc_admin where id > 0'; $list = $db->getList($sqlList); var_dump($list); $sqlCount = 'select count(*) as num from jcc_admin where id > 0'; $count = $db->getCount($sqlCount); var_dump($count);
<?php session_start(); require_once 'core/Database.php'; // Sistema para validar usuário após o login $usuario = $_POST['usuario']; $senha = $_POST['senha']; $db = new Database(); $login = $db->getRow("SELECT * FROM admin WHERE usuario='{$usuario}' AND senha='{$senha}'"); if ($login) { $_SESSION['sessao'] = sha1(time()); $_SESSION['usuario'] = $usuario; header('Location: dashboard.php'); } else { header('Location: login.php'); session_destroy(); }
$d->close(); } $target_dir = WEB_ROOT . 'images/notes'; // remove old images clearDirectory( $target_dir ); // create new $db = new Database( "db13310_notes" ); $sql = "SELECT id,image_full,image_full_back FROM notes"; $query = $db->query($sql); $items = array(); while($row = $db->getRow($query)){ $items[] = $row; } if( isset( $_GET['id'] ) ) { $images = Note::getAll( array( "id" => $_GET['id'] ) ); } foreach($items as $item) { if( isset( $item['image_full'] ) ) createImage( $item, 'image_full' ); if( isset( $item['image_full_back'] ) ) createImage( $item, 'image_full_back', '_back' ); } function createImage( $item, $data_field, $suffix = '' )
function getAll($order = null, $order_by = null) { if (!is_null($this->db)) { $db = $this->db; } else { $db = new Database("db13310_notes"); } $sql = "SELECT * FROM location "; if (!is_null($order)) { $sql .= "ORDER BY " . $order . " "; $sql .= !is_null($order_by) ? $order_by : "ASC"; } $result = $db->query($sql); $categories = array(); while ($row = $db->getRow($result)) { $categories[] = array("id" => $row['id'], "title" => $row['city'] . " (" . (!is_null($row['state']) ? $row['state'] : $row['country']) . ")"); } return $categories; }
public function testGetRowAndProperty() { $db = new Database(); $stmt = $db->prepare('SELECT username FROM Users WHERE id = 1'); $stmt->execute(); $username = $db->getRow($stmt)->username; $this->assertEquals('*****@*****.**', $username); }
<link rel="stylesheet" type="text/css" href="style.css"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> </head> <body> <?php include_once 'database.php'; include_once 'lrc_questline.php'; session_start(); if (isset($_POST["username"])) { $_SESSION["message"] = array(); $username = $_POST["username"]; if ($username === "") { echo "<script>window.location.href='index.php'</script>"; } $username = strtok($username, "@"); $row = Database::getRow("User", "username='******'"); $id = $row["id"]; $user = new User($row["id"]); $_SESSION["user"] = $user; $_SESSION["quest"] = $user->quests["LRC"]; $_SESSION["history"] = array(); } else { if (isset($_POST["answer"])) { $user = $_SESSION["user"]; $quest = $_SESSION["quest"]; $answer = $_POST["answer"]; $_POST = array(); $quest->submit($answer); if ($quest->validate($user)) { array_push($_SESSION["message"], "<p class='msg-correct'>CORRECT!</p>"); $quest->save($user->getId());
require_once 'functions.php'; require_once 'dbConfig.php'; require_once 'config.php'; require_once 'database.php'; date_default_timezone_set(Config::timezone()); $id = loadvar('id'); $fieldname = loadvar('fieldname'); $p = loadvar('p'); $db = new Database(); if ($id != '' && $fieldname != '') { if ($p == 'show') { //show image $query = 'select AES_DECRYPT(picture, "' . Config::filePictureKey() . '") as picture1 from ' . Config::dbSurveyData() . '_pictures where primkey="' . $id . '" and variablename = "' . $fieldname . '"'; $result = $db->selectQuery($query); if ($result != null && $db->getNumberOfRows($result) > 0) { $row = $db->getRow($result); ob_clean(); header('Content-type: image/jpg'); if ($row['picture'] != null) { print $row['picture1']; } else { //display 'empty' image ob_clean(); header('Content-type: image/jpg'); echo file_get_contents('../../images/nopicture.png'); } exit; } else { //display 'empty' image ob_clean(); header('Content-type: image/jpg');
$db = new Database(); // prepare query $db->prepareQuery($query); // execute query $result = $db->executeQuery(); //$result = $db->resultset(); // execute the query if (!$result) { die("Could not query the database: <br />"); } // else { echo "Successfully queried the database.<br>"; } // for debugging // the index term list $studynumberList = array(); echo "<form action='da_catalog_titleRecord.php' method='put' name='studynumber' target='_self'>"; echo "<select name='studynumber' class='alphaTitleList'>"; $row_index = 0; while ($row = $db->getRow()) { $title = $row['Title']; $tempStudynumber = $row['StudyNum']; // code to insure that the studynumbers sort correctly $numeric_only = preg_replace('/[a-zA-Z]/', '', $tempStudynumber); $numeric_only = str_pad($numeric_only, 10, "0", STR_PAD_LEFT); $alpha_only = preg_replace("/[0-9]/", '', $tempStudynumber); //$alpha_only = str_pad($numeric_only, 6, "0", STR_PAD_LEFT); //echo $numeric_only; $studynumberList[$row_index]["alpha"] = $alpha_only; $studynumberList[$row_index]["num"] = str_pad($numeric_only, 6, "0", STR_PAD_LEFT); //$studynumberList[$row_index]["sort_num"] = $alpha_only . $numeric_only; $studynumberList[$row_index]["studynum"] = $tempStudynumber; // echo str_pad($input, 10, "-=", STR_PAD_LEFT); //echo $studynumber . "<br>"; //echo "<li class='alphaTitleList'><A HREF= '" . $currentHTTP . "da_catalog_titleRecord.php?studynumber=$studynumber&title=$title'>$studynumber</a></li>";
/** * @param Database $db * @param array $runRows: one or more rows from the `runs` table. * @return array with properties 'runs' and 'userAgents' */ public static function getDataFromRunRows(Database $db, $runRows) { $userAgentIDs = array(); $runs = array(); foreach ($runRows as $runRow) { $runInfo = array('id' => $runRow->id, 'name' => $runRow->name, 'url' => $runRow->url); $runUaRuns = array(); // Get list of useragents that this run is scheduled for $runUaRows = $db->getRows(str_queryf('SELECT status, useragent_id, results_id FROM run_useragent WHERE run_useragent.run_id = %u;', $runRow->id)); if ($runUaRows) { foreach ($runUaRows as $runUaRow) { // Add UA ID to the list. After we've collected // all the UA IDs we'll perform one query for all of them // to gather the info from the useragents table $userAgentIDs[] = $runUaRow->useragent_id; if (!$runUaRow->results_id) { $runUaRuns[$runUaRow->useragent_id] = array('runStatus' => 'new'); } else { $runresultsRow = $db->getRow(str_queryf('SELECT client_id, status, total, fail, error FROM runresults WHERE id = %u;', $runUaRow->results_id)); if (!$runresultsRow) { $this->setError('data-corrupt'); return; } $runUaRuns[$runUaRow->useragent_id] = array('useragentID' => $runUaRow->useragent_id, 'clientID' => $runresultsRow->client_id, 'failedTests' => $runresultsRow->fail, 'totalTests' => $runresultsRow->total, 'errors' => $runresultsRow->error, 'runStatus' => self::getRunresultsStatus($runresultsRow), 'runResultsUrl' => swarmpath('result/' . $runUaRow->results_id), 'runResultsLabel' => $runresultsRow->status != ResultAction::$STATE_FINISHED ? '' : ($runresultsRow->error > 0 ? $runresultsRow->error : ($runresultsRow->fail > 0 ? $runresultsRow->fail : $runresultsRow->total))); } } natcaseksort($runUaRuns); $runs[] = array('info' => $runInfo, 'uaRuns' => $runUaRuns); } } // Get information for all encounted useragents $swarmUaIndex = BrowserInfo::getSwarmUAIndex(); $userAgents = array(); foreach ($userAgentIDs as $userAgentID) { if (!isset($swarmUaIndex->{$userAgentID})) { throw new SwarmException("Job {$jobID} has runs for unknown brower ID `{$userAgentID}`."); } else { $userAgents[$userAgentID] = (array) $swarmUaIndex->{$userAgentID}; } } natcaseksort($userAgents); return array('runs' => $runs, 'userAgents' => $userAgents); }
color: #00FF00; } </style> </head> <body> <h1>AnthroPosts - Mechanical Turk</h1> <? $sql = "SELECT * FROM `notes` AS n "; $result = $db->query($sql); echo "<ol id='list'>"; while($row = $db->getRow($result)) { $title = str_replace("\n"," \ ",$row['content']); $mp3 = "../mp3s/".$row['id'].".mp3"; if(file_exists($mp3)) { echo "<li>"; echo "<a href='../admin/index.php?id=".$row['id']."' target='_blank'>".$title."</a>"; echo "<div>"; echo '<object width="160" height="20" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab">'; echo '<param name="src" value="'.$mp3.'">'; echo '<param name="autoplay" value="false">'; echo '<param name="controller" value="true">'; echo '<embed src="'.$mp3.'" width="160" height="20" autoplay="false" controller="true" pluginspage="http://www.apple.com/quicktime/download/"></embed>'; echo '</object>';
/** * */ public function testLogErrorInsertedToDatabase() { $db = new Database(); $get_logcount_stmt = $db->prepare('SELECT count(id) AS num_logs FROM Logs'); $get_logcount_stmt->execute(); $row = $db->getRow($get_logcount_stmt); Console::logError('test', 'file.php', '111'); $logs = Console::getLogs(); $this->assertEquals($row->num_logs + 1, $logs[0]['id']); }