select() static public method

Returns multiple rows from a table
static public select ( string $table, mixed $select = '*', mixed $where = null, string $order = null, integer $page = null, integer $limit = null, boolean $fetch = true ) : mixed
$table string The table name
$select mixed Either an array of fields or a MySQL string of fields
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
$order string Order clause without the order keyword. ie: "added desc"
$page integer a page number
$limit integer a number for rows to return
$fetch boolean true: apply db::fetch(), false: don't apply db::fetch()
return mixed
Example #1
0
 public function mostrar_usuarios()
 {
     $array = array();
     parent::__construct($this->db, $this->tabla);
     parent::select($array);
     parent::mostrar_resultados();
 }
Example #2
0
 /**
  * Overriding __get() to allow for self relations with parent_id
  * 
  * @param mixed $key the key to return
  *
  * @return mixed
  */
 public function __get($key)
 {
     if ('parent_id' == $key) {
         return db::select(array_keys($this->_data))->from($this->_table_name)->where('id', '=', $this->_data['parent_id'])->as_object('Model_Category')->execute($this->_db)->current();
     }
     return parent::__get($key);
 }
Example #3
0
 /**
  * Checks if a session is active.
  *
  * @param   mixed    role name string, role ORM object, or array with role names
  * @return  boolean
  */
 public function logged_in($role = NULL)
 {
     $status = FALSE;
     // Get the user from the session
     $user = $this->get_user();
     if (is_object($user) and $user instanceof Model_User and $user->id) {
         // Everything is okay so far
         $status = TRUE;
         if (!empty($role)) {
             // Multiple roles to check
             if (is_array($role)) {
                 // Check each role
                 foreach ($role as $_role) {
                     if (!is_numeric($_role)) {
                         $_role = AutoModeler_ORM::factory('role')->load(db::select()->where('name', '=', $_role))->id;
                     }
                     // If the user doesn't have the role
                     if (!$user->has('roles', $_role)) {
                         // Set the status false and get outta here
                         $status = FALSE;
                         break;
                     }
                 }
             } else {
                 if (!is_numeric($role)) {
                     // Load the role
                     $role = AutoModeler_ORM::factory('role')->load(db::select()->where('name', '=', $role))->id;
                 }
                 // Check that the user has the given role
                 $status = $user->has('roles', $role);
             }
         }
     }
     return $status;
 }
Example #4
0
    function siteMap()
    {
        db::table('pages');
        db::where('site_id', ADMIN_SITE_ID);
        db::where('page_map', '1');
        db::where('page_dynamic', '0');
        $res = db::select();
        $content = '';
        while ($row = mysql_fetch_assoc($res)) {
            $content .= '
<url>
	<loc>http://' . ADMIN_SITE . $row['page_folder'] . '</loc>
	<lastmod>' . substr($row['page_date'], 0, 10) . '</lastmod>
</url>';
        }
        $xml = '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">' . $content . '
</urlset>';
        if (files::write(ROOT . '/sitemap.xml', $xml)) {
            buffer::set('sitemap.xml успешно создан.');
        } else {
            buffer::set('Не удалось записать sitemap.xml.');
        }
    }
Example #5
0
 /**
  * Generate RSS 2.0 feed
  *
  * @return string RSS 2.0 xml
  */
 public function create_feed()
 {
     ob_clean();
     $xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
     $xml .= '<rss version="2.0">' . "\n";
     // channel required properties
     $xml .= '<channel>' . "\n";
     $xml .= '<title>test</title>' . "\n";
     $xml .= '<link>test</link>' . "\n";
     $xml .= '<description>test</description>' . "\n";
     // channel optional properties
     $db = new db();
     $query = "SELECT postid, posttitle, postdescription FROM article  ORDER BY postid DESC LIMIT 15";
     // get RSS channel items
     //$now =  date("YmdHis"); // get current time  // configure appropriately to your environment
     $rss_items = $db->select($query);
     //var_dump($rss_items);die;
     foreach ($rss_items as $rss_item) {
         $xml .= '<item>' . "\n";
         $xml .= '<title>' . $rss_item['posttitle'] . '</title>' . "\n";
         $xml .= '<description>' . $rss_item['postdescription'] . '</description>' . "\n";
         /* $xml .= '<category>' . $rss_item['category'] . '</category>' . "\n";
            $xml .= '<source>' . $rss_item['source'] . '</source>' . "\n";*/
         $xml .= '</item>' . "\n";
     }
     $xml .= '</channel>';
     $xml .= '</rss>';
     //var_dump($xml);
     return $xml;
 }
 private static function get_cached($id)
 {
     $track_data = db::select('audio_cache', 'track_data', array('id' => $id));
     if (empty($track_data)) {
         return false;
     }
     return (array) json_decode($track_data[0]['track_data']);
 }
Example #7
0
 public function edit($id)
 {
     $db = new db();
     $query = "select * from users where userid = '{$id}'";
     $result = $db->select($query);
     //var_dump($result);die;
     return $result;
 }
 public function get_ingredientes()
 {
     $array = array();
     parent::__construct($this->db, $this->tabla);
     parent::select($array);
     $this->resultado = parent::__get("resultado");
     var_dump($this->resultado);
 }
Example #9
0
 private static function get_cached($video_id)
 {
     $video_data = db::select('video_cache', 'video_data', array('id' => $video_id));
     if (!empty($video_data)) {
         return json_decode($video_data[0]['video_data']);
     } else {
         return false;
     }
 }
 public static function getPadaliniai($idParamosPriemone)
 {
     $result = db::select("SELECT * FROM `PPOS`.`ParamosAdministravimas` WHERE ParamosPriemone = " . $idParamosPriemone);
     if ($result["bool"] == true) {
         return $result["data"];
     } else {
         return $result;
     }
 }
Example #11
0
 function load()
 {
     db::table('mails');
     db::where('site_id', SITE_ID);
     $res = db::select();
     while ($row = mysql_fetch_assoc($res)) {
         self::$mails[$row['mail_name']] = $row;
     }
 }
Example #12
0
 function loadBlocks($site_id = 1)
 {
     db::table('blocks');
     db::where('site_id', $site_id);
     db::where('block_pub', '1');
     $res = db::select('block_id', 'block_title', 'block_name', 'block_pub');
     while ($row = mysql_fetch_assoc($res)) {
         self::$blocks[$row['block_id']] = $row['block_name'];
     }
 }
Example #13
0
 public function listar(db $db)
 {
     $db->clear();
     $db->setTabela('funcionarios AS A, cargos AS B');
     $db->setCondicao(" A.status_funcionario in('" . status::ATIVO . "') AND A.id_cargo = B.id_cargo");
     $campos = array('A.id_funcionario', 'A.codigo_funcionario', 'A.foto_funcionario', 'A.nome_funcionario', 'A.sobrenome_funcionario', 'B.nome_cargo', 'B.setor_cargo', 'A.cpf_funcionario', 'A.status_funcionario', 'A.timestamp');
     if ($db->select($campos)) {
         return $db->resultAll();
     }
 }
Example #14
0
 function loadTmpls($site_id = 1)
 {
     db::table('templates');
     db::where('site_id', $site_id);
     db::where('tmpl_pub', '1');
     $res = db::select();
     while ($row = mysql_fetch_assoc($res)) {
         self::$tmpls[$row['tmpl_id']] = $row['tmpl_name'];
     }
 }
Example #15
0
 function loadMenus($site_id)
 {
     db::table('menus');
     db::where('site_id', $site_id);
     db::where('menu_pub', '1');
     $res = db::select();
     while ($row = mysql_fetch_assoc($res)) {
         self::$menus[$row['menu_id']] = $row['menu_name'];
     }
 }
Example #16
0
 public function consultar(db $db, caixasModel $caixa)
 {
     $db->clear();
     $db->setTabela('caixas');
     $db->setCondicao("id_caixa = '" . $caixa->getId() . "'");
     if ($db->select()) {
         return $db->result();
     } else {
         return null;
     }
 }
Example #17
0
 public function consultar(db $db, caixasModel $caixa)
 {
     $db->clear();
     $db->setTabela('caixas');
     $db->setCondicao("ip_maquina = ? ");
     $db->setParameter(1, $caixa->getIp());
     if ($db->select()) {
         return $db->result();
     } else {
         return null;
     }
 }
 public function consultar(db $db, funcionariosModel $funcionario, $status)
 {
     $db->clear();
     $db->setTabela('funcionarios');
     $db->setCondicao("id_funcionario = ? and status_funcionario in ('" . implode("','", $status) . "')");
     $db->setParameter(1, $funcionario->getId());
     if ($db->select()) {
         return $db->result();
     } else {
         return null;
     }
 }
Example #19
0
 function checkDuplicate()
 {
     db::table('mails');
     if (params::get('mail_id')) {
         db::where('mail_id', params::get('mail_id'), '!=');
     }
     db::where('mail_name', params::get('value'));
     db::select('mail_id');
     if (db::rows() != 0) {
         buffer::set('error');
     }
 }
Example #20
0
 function view()
 {
     db::table('news');
     db::order('news_date', 'DESC');
     $res = db::select();
     while ($row = mysql_fetch_assoc($res)) {
         $row = filter::get('news_pub', array('unpub', 'pub'), $row);
         $row['news_title'] = strip_tags($row['news_title']);
         $row['news_date'] = dt::date2print('%d %F %Y, %H:%i', $row['news_date']);
         s::roll('news', $row);
     }
 }
Example #21
0
 function view()
 {
     db::table('admin_log_actions');
     db::join('admin_users', 'admin_log_actions', 'user_id');
     db::order('log_date', 'DESC');
     db::limit(30);
     $res = db::select();
     while ($row = mysql_fetch_assoc($res)) {
         $row['log_date'] = dt::format('%d.%m.%Y %H:%M', $row['log_date']);
         s::roll('logs_list', $row);
     }
 }
Example #22
0
 function show()
 {
     $event = web::getEvent();
     if ($event === false) {
         $year = date('Y');
     } else {
         $year = $event;
     }
     s::set('info_date_select', htmlspecialchars($year));
     $sql = "SELECT `section_year` as date FROM `info_sections` WHERE `section_view`='0'  GROUP BY `date` ORDER BY `date` DESC";
     $res = db::query($sql);
     $rows = mysql_num_rows($res);
     if ($rows > 1) {
         s::add('info_date_selector', '<ul class="years">');
         while ($row = mysql_fetch_assoc($res)) {
             if ($row['date'] == $year) {
                 $row['date'] = '<li><span>' . $row['date'] . '</span></li>';
             } else {
                 $row['date'] = '<li><a href="' . web::get('page_folder') . '' . $row['date'] . '/">' . $row['date'] . '</a></li>';
             }
             s::add('info_date_selector', $row['date']);
         }
         s::add('info_date_selector', '</ul>');
     }
     $files = array();
     db::table('info_files');
     $r = db::select();
     while ($a = mysql_fetch_assoc($r)) {
         $files[$a['section_id']][] = $a;
     }
     db::table('info_sections');
     db::order('section_order', 'DESC');
     db::where('section_year', $year);
     $r = db::select();
     if (db::rows() == 0) {
         web::error404();
     }
     while ($a = mysql_fetch_assoc($r)) {
         if ($a['section_view'] == '0') {
             s::roll('sections', $a);
         } else {
             s::roll('sections_view', $a);
         }
         if (isset($files[$a['section_id']])) {
             foreach ($files[$a['section_id']] as $v) {
                 $v['file_icon'] = files::getFileIco($v['file_type']);
                 $v['file_size'] = files::parseSizeSmart($v['file_size']);
                 s::roll('items' . $a['section_id'], $v);
             }
         }
     }
 }
Example #23
0
 private function analyzeTables()
 {
     $data = db::select("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . $this->dbname . "'");
     foreach ($data['data'] as $d) {
         $columns = db::select("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE (TABLE_NAME = '" . $d['TABLE_NAME'] . "') AND (TABLE_SCHEMA = '" . $this->dbname . "')");
         $columnsArray = array();
         foreach ($columns['data'] as $c) {
             $columnsArray[] = $c['COLUMN_NAME'];
         }
         $tables[$d['TABLE_NAME']] = $columnsArray;
     }
     return $tables;
 }
Example #24
0
File: lists.php Project: rigidus/ea
 function country($array = false, $rollname = 'country')
 {
     $country = array();
     db::table('country');
     $res = db::select();
     while ($row = mysql_fetch_assoc($res)) {
         if ($array) {
             $country[$row['country_id']] = $row['country_name'];
         }
         s::roll($rollname, $row);
     }
     return $country;
 }
Example #25
0
 /**
  * Find a token
  *
  * @param string $refresh_token the token to find
  * @param int    $client_id     the optional client id to find with
  * 
  * @return stdClass | null
  */
 public static function find_token($refresh_token, $client_id = NULL)
 {
     $query = db::select('*')->from('oauth2_refresh_tokens')->where('code', '=', $client_id)->where('expires', '>=', time());
     if (NULL !== $client_id) {
         $query->where('client_id', '=', $client_id);
     }
     $result = $query->as_object('Model_OAuth2_Refresh_Token', array(array('loaded' => TRUE, 'saved' => TRUE)))->execute();
     if (count($result)) {
         return $result->current();
     } else {
         return new Model_OAuth2_Refresh_Token();
     }
 }
Example #26
0
 /**
  * Find a client
  *
  * @param int    $client_id     the client to find
  * @param string $client_secret the secret to find with
  * 
  * @return stdClass | null
  */
 public static function find_client($client_id, $client_secret = NULL)
 {
     $query = db::select('*')->from('oauth2_clients')->where('client_id', '=', $client_id);
     if (NULL !== $client_secret) {
         $query->where('client_id', '=', $client_secret);
     }
     $result = $query->as_object('Model_OAuth2_Client', array(array('loaded' => TRUE, 'saved' => TRUE)))->execute();
     if (count($result)) {
         return $result->current();
     } else {
         return new Model_OAuth2_Client();
     }
 }
Example #27
0
 private function recursiveLevelUpdate($parent_id, $level)
 {
     static $counter = 0;
     $counter++;
     $items = db::select('*')->from(':table:')->where('parent = %i', $parent_id)->fetchAll();
     foreach ($items as $key => $item) {
         $update = $level + $counter;
         $values = array('level' => $update);
         db::update(':table:', $values)->where('id = %i', $item->id)->execute();
         $items[$key]['items'] = $this->recursiveLevelUpdate($item->id, $level);
     }
     return $items;
 }
Example #28
0
 function view()
 {
     events::observe('upload', 'index');
     events::observer();
     $dir = IMAGES_PATH . 'index/';
     db::table('images');
     $r = db::select();
     while ($a = mysql_fetch_assoc($r)) {
         $a = filter::get('img_set', array('unpub', 'pub'), $a);
         $a['thumb'] = $dir . $a['img_id'] . '_m.jpg';
         s::roll('images', $a);
     }
 }
 public static function generatateResources($player_id)
 {
     $db = new db();
     $player = $db->select("player", "*", "player_id = '" . $player_id . "'");
     $planet = $db->select("planets", "*", "player_id = '" . $player_id . "'");
     //Zeitdifferenz der letzten aktivität in Stunden
     $lastActive = new DateTime($player['lastActive']);
     $now = new DateTime("now");
     $now_f = $now->format("Y-m-d H:i:s");
     $lastActive_f = $lastActive->format("Y-m-d H:i:s");
     $timeDiff = self::time_diff($now_f, $lastActive_f);
     //----------------------------------------------
     $production = self::getProdFormel($player_id);
     $storage = self::getMaxStorage($player_id);
     //Produktion pro Stunde
     $production['m'] *= $timeDiff;
     $production['c'] *= $timeDiff;
     $production['d'] *= $timeDiff;
     $production['mo'] *= $timeDiff;
     $production['e'] *= $timeDiff;
     //---------------------------------
     $gelagert['m'] = $planet['metal'];
     $gelagert['c'] = $planet['crystal'];
     $gelagert['d'] = $planet['deuterium'];
     $gelagert['mo'] = $planet['money'];
     $gelagert['e'] = $planet['energy'];
     foreach ($production as $key => $p) {
         $newStorage = $gelagert[$key] + $p;
         $temp = self::realProduced($newStorage, $storage[$key]);
         if ($temp === true) {
             $prod[$key] = $storage[$key] - $gelagert[$key];
         } else {
             $prod[$key] = $p;
         }
     }
     $db->update("planets", "metal = metal + " . round($prod['m'], 6) . ", \n\t\t\t\t\t\t\t\t\t\t\tcrystal = crystal + " . round($prod['c'], 6) . ", \n\t\t\t\t\t\t\t\t\t\t\tdeuterium = deuterium + " . round($prod['d'], 6) . ",\n\t\t\t\t\t\t\t\t\t\t\tenergy = energy + " . round($prod['e'], 6) . ",\n\t\t\t\t\t\t\t\t\t\t\tmoney = money + " . round($prod['mo'], 6), "player_id = '" . $player_id . "'");
     $db->update("player", "lastActive = '" . $now_f . "'", "player_id = '" . $player_id . "'");
 }
Example #30
0
 public function consultar(db $db, produtosModel $produto, $status)
 {
     try {
         $db->clear();
         $db->setTabela('produtos as a, categorias as b , marcas as c');
         $db->setCondicao("a.id_produto = ? and b.id_categoria = a.id_categoria and c.id_marca = a.id_marca AND a.status_produto in ('" . implode("','", $status) . "')");
         $db->setParameter(1, $produto->getId());
         if ($db->select()) {
             return $db->result();
         }
     } catch (dbException $e) {
         return $e->gerMessageErro();
     }
 }