当前位置: 首页>>代码示例>>PHP>>正文


PHP Dba类代码示例

本文整理汇总了PHP中Dba的典型用法代码示例。如果您正苦于以下问题:PHP Dba类的具体用法?PHP Dba怎么用?PHP Dba使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Dba类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: build_cache

 /**
  * build_cache
  * Build a cache based on the array of ids passed, saves lots of little queries
  */
 public static function build_cache($ids = array())
 {
     if (!is_array($ids) or !count($ids)) {
         return false;
     }
     $idlist = '(' . implode(',', $ids) . ')';
     $sql = "SELECT * FROM `video` WHERE `video`.`id` IN {$idlist}";
     $db_results = Dba::read($sql);
     while ($row = Dba::fetch_assoc($db_results)) {
         parent::add_to_cache('video', $row['id'], $row);
     }
 }
开发者ID:axelsimon,项目名称:ampache,代码行数:16,代码来源:video.class.php

示例2: get_info

 /**
  * get_info
  * retrieves the info from the database and puts it in the cache
  */
 public function get_info($id, $table_name = '')
 {
     $table_name = $table_name ? Dba::escape($table_name) : Dba::escape(strtolower(get_class($this)));
     // Make sure we've got a real id
     if (!is_numeric($id)) {
         return array();
     }
     if (self::is_cached($table_name, $id)) {
         return self::get_from_cache($table_name, $id);
     }
     $sql = "SELECT * FROM `{$table_name}` WHERE `id`='{$id}'";
     $db_results = Dba::read($sql);
     if (!$db_results) {
         return array();
     }
     $row = Dba::fetch_assoc($db_results);
     self::add_to_cache($table_name, $id, $row);
     return $row;
 }
开发者ID:axelsimon,项目名称:ampache,代码行数:23,代码来源:database_object.abstract.php

示例3: rebuild_all_preferences

 /**
  * rebuild_all_preferences
  * This rebuilds the user preferences for all installed users, called by the plugin functions
  */
 public static function rebuild_all_preferences()
 {
     // Clean out any preferences garbage left over
     $sql = "DELETE `user_preference`.* FROM `user_preference` " . "LEFT JOIN `user` ON `user_preference`.`user` = `user`.`id` " . "WHERE `user_preference`.`user` != -1 AND `user`.`id` IS NULL";
     Dba::write($sql);
     // Get only users who has less preferences than excepted
     // otherwise it would have significant performance issue with large user database
     $sql = "SELECT `user` FROM `user_preference` " . "GROUP BY `user` HAVING COUNT(*) < (" . "SELECT COUNT(`id`) FROM `preference` WHERE `catagory` != 'system')";
     $db_results = Dba::read($sql);
     while ($row = Dba::fetch_assoc($db_results)) {
         User::fix_preferences($row['user']);
     }
     return true;
 }
开发者ID:bl00m,项目名称:ampache,代码行数:18,代码来源:user.class.php

示例4: get

 /**
  * get
  * This functions returns an array containing information about
  * The songs that vlc currently has in it's playlist. This must be
  * done in a standardized fashion
  * Warning ! if you got files in vlc medialibary those files will be sent to the php xml parser
  * to, not to your browser but still this can take a lot of work for your server.
  * The xml files of vlc need work, not much documentation on them....
  */
 public function get()
 {
     /* Get the Current Playlist */
     $list = $this->_vlc->get_tracks();
     if (!$list) {
         return array();
     }
     $counterforarray = 0;
     // here we look if there are song in the playlist when media libary is used
     if ($list['node']['node'][0]['leaf'][$counterforarray]['attr']['uri']) {
         while ($list['node']['node'][0]['leaf'][$counterforarray]) {
             $songs[] = htmlspecialchars_decode($list['node']['node'][0]['leaf'][$counterforarray]['attr']['uri'], ENT_NOQUOTES);
             $songid[] = $list['node']['node'][0]['leaf'][$counterforarray]['attr']['id'];
             $counterforarray++;
         }
         // if there is only one song look here,and media libary is used
     } elseif ($list['node']['node'][0]['leaf']['attr']['uri']) {
         $songs[] = htmlspecialchars_decode($list['node']['node'][0]['leaf']['attr']['uri'], ENT_NOQUOTES);
         $songid[] = $list['node']['node'][0]['leaf']['attr']['id'];
     } elseif ($list['node']['node']['leaf'][$counterforarray]['attr']['uri']) {
         while ($list['node']['node']['leaf'][$counterforarray]) {
             $songs[] = htmlspecialchars_decode($list['node']['node']['leaf'][$counterforarray]['attr']['uri'], ENT_NOQUOTES);
             $songid[] = $list['node']['node']['leaf'][$counterforarray]['attr']['id'];
             $counterforarray++;
         }
     } elseif ($list['node']['node']['leaf']['attr']['uri']) {
         $songs[] = htmlspecialchars_decode($list['node']['node']['leaf']['attr']['uri'], ENT_NOQUOTES);
         $songid[] = $list['node']['node']['leaf']['attr']['id'];
     } else {
         return array();
     }
     $counterforarray = 0;
     foreach ($songs as $key => $entry) {
         $data = array();
         /* Required Elements */
         $data['id'] = $songid[$counterforarray];
         // id number of the files in the vlc playlist, needed for other operations
         $data['raw'] = $entry;
         $url_data = $this->parse_url($entry);
         switch ($url_data['primary_key']) {
             case 'oid':
                 $data['oid'] = $url_data['oid'];
                 $song = new Song($data['oid']);
                 $song->format();
                 $data['name'] = $song->f_title . ' - ' . $song->f_album . ' - ' . $song->f_artist;
                 $data['link'] = $song->f_link;
                 break;
             case 'demo_id':
                 $democratic = new Democratic($url_data['demo_id']);
                 $data['name'] = T_('Democratic') . ' - ' . $democratic->name;
                 $data['link'] = '';
                 break;
             case 'random':
                 $data['name'] = T_('Random') . ' - ' . scrub_out(ucfirst($url_data['type']));
                 $data['link'] = '';
                 break;
             default:
                 /* If we don't know it, look up by filename */
                 $filename = Dba::escape($entry);
                 $sql = "SELECT `name` FROM `live_stream` WHERE `url`='{$filename}' ";
                 $db_results = Dba::read($sql);
                 if ($row = Dba::fetch_assoc($db_results)) {
                     //if stream is known just send name
                     $data['name'] = htmlspecialchars(substr($row['name'], 0, 50));
                 } elseif (strncmp($entry, 'http', 4) == 0) {
                     $data['name'] = htmlspecialchars("(VLC stream) " . substr($entry, 0, 50));
                 } else {
                     $getlast = explode("/", $entry);
                     $lastis = count($getlast) - 1;
                     $data['name'] = htmlspecialchars("(VLC local) " . substr($getlast[$lastis], 0, 50));
                 }
                 // end if loop
                 break;
         }
         // end switch on primary key type
         $data['track'] = $key + 1;
         $counterforarray++;
         $results[] = $data;
     }
     // foreach playlist items
     return $results;
 }
开发者ID:cheese1,项目名称:ampache,代码行数:91,代码来源:vlc.controller.php

示例5: update_380005

 /**
  * update_380005
  *
  * Add manual update flag on artist
  */
 public static function update_380005()
 {
     $retval = true;
     $sql = "ALTER TABLE `artist` ADD COLUMN `manual_update` SMALLINT( 1 ) DEFAULT '0'";
     $retval &= Dba::write($sql);
     return $retval;
 }
开发者ID:bl00m,项目名称:ampache,代码行数:12,代码来源:update.class.php

示例6: get

 /**
  * get_songs
  * This functions returns an array containing information about
  * the songs that MPD currently has in its playlist. This must be
  * done in a standardized fashion
  */
 public function get()
 {
     // If we don't have the playlist yet, pull it
     if (!isset($this->_mpd->playlist)) {
         $this->_mpd->RefreshInfo();
     }
     /* Get the Current Playlist */
     $playlist = $this->_mpd->playlist;
     foreach ($playlist as $entry) {
         $data = array();
         /* Required Elements */
         $data['id'] = $entry['Pos'];
         $data['raw'] = $entry['file'];
         $url_data = $this->parse_url($entry['file']);
         switch ($url_data['primary_key']) {
             case 'oid':
                 $data['oid'] = $url_data['oid'];
                 $song = new Song($data['oid']);
                 $song->format();
                 $data['name'] = $song->f_title . ' - ' . $song->f_album . ' - ' . $song->f_artist;
                 $data['link'] = $song->f_link;
                 break;
             case 'demo_id':
                 $democratic = new Democratic($url_data['demo_id']);
                 $data['name'] = T_('Democratic') . ' - ' . $democratic->name;
                 $data['link'] = '';
                 break;
             case 'random':
                 $data['name'] = T_('Random') . ' - ' . scrub_out(ucfirst($url_data['type']));
                 $data['link'] = '';
                 break;
             default:
                 /* If we don't know it, look up by filename */
                 $filename = Dba::escape($entry['file']);
                 $sql = "SELECT `id`,'song' AS `type` FROM `song` WHERE `file` LIKE '%{$filename}' " . "UNION ALL " . "SELECT `id`,'live_stream' AS `type` FROM `live_stream` WHERE `url`='{$filename}' ";
                 $db_results = Dba::read($sql);
                 if ($row = Dba::fetch_assoc($db_results)) {
                     $media = new $row['type']($row['id']);
                     $media->format();
                     switch ($row['type']) {
                         case 'song':
                             $data['name'] = $media->f_title . ' - ' . $media->f_album . ' - ' . $media->f_artist;
                             $data['link'] = $media->f_link;
                             break;
                         case 'live_stream':
                             $frequency = $media->frequency ? '[' . $media->frequency . ']' : '';
                             $site_url = $media->site_url ? '(' . $media->site_url . ')' : '';
                             $data['name'] = "{$media->name} {$frequency} {$site_url}";
                             $data['link'] = $media->site_url;
                             break;
                     }
                     // end switch on type
                 } else {
                     $data['name'] = T_('Unknown');
                     $data['link'] = '';
                 }
                 break;
         }
         // end switch on primary key type
         /* Optional Elements */
         $data['track'] = $entry['Pos'] + 1;
         $results[] = $data;
     }
     // foreach playlist items
     return $results;
 }
开发者ID:nioc,项目名称:ampache,代码行数:72,代码来源:mpd.controller.php

示例7: remove_plugin_version

 /**
  * remove_plugin_version
  * This removes the version row from the db done on uninstall
  */
 public function remove_plugin_version()
 {
     $name = Dba::escape('Plugin_' . $this->_plugin->name);
     $sql = "DELETE FROM `update_info` WHERE `key`='{$name}'";
     Dba::write($sql);
     return true;
 }
开发者ID:ivan801,项目名称:ampache,代码行数:11,代码来源:plugin.class.php

示例8: save_objects

 /**
  * save_objects
  * This takes the full array of object ids, often passed into show and
  * if necessary it saves them
  */
 public function save_objects($object_ids)
 {
     // Saving these objects has two operations, one holds it in
     // a local variable and then second holds it in a row in the
     // tmp_browse table
     // Only do this if it's not a simple browse
     if (!$this->is_simple()) {
         $this->_cache = $object_ids;
         $this->set_total(count($object_ids));
         $id = $this->id;
         if ($id != 'nocache') {
             $data = self::_serialize($this->_cache);
             $sql = 'UPDATE `tmp_browse` SET `object_data` = ? ' . 'WHERE `sid` = ? AND `id` = ?';
             Dba::write($sql, array($data, session_id(), $id));
         }
     }
     return true;
 }
开发者ID:axelsimon,项目名称:ampache,代码行数:23,代码来源:query.class.php

示例9: get_access_lists

 /**
  * get_access_lists
  * returns a full listing of all access rules on this server
  */
 public static function get_access_lists()
 {
     $sql = 'SELECT `id` FROM `access_list`';
     $db_results = Dba::read($sql);
     $results = array();
     while ($row = Dba::fetch_assoc($db_results)) {
         $results[] = $row['id'];
     }
     return $results;
 }
开发者ID:axelsimon,项目名称:ampache,代码行数:14,代码来源:access.class.php

示例10: check_local_mp3

 /**
  * check_local_mp3
  * Checks the song to see if it's there already returns true if found, false if not
  */
 public function check_local_mp3($full_file, $gather_type = '')
 {
     $file_date = filemtime($full_file);
     if ($file_date < $this->last_add) {
         debug_event('Check', 'Skipping ' . $full_file . ' File modify time before last add run', '3');
         return true;
     }
     $sql = "SELECT `id` FROM `song` WHERE `file` = ?";
     $db_results = Dba::read($sql, array($full_file));
     //If it's found then return true
     if (Dba::fetch_row($db_results)) {
         return true;
     }
     return false;
 }
开发者ID:cheese1,项目名称:ampache,代码行数:19,代码来源:local.catalog.php

示例11: get_all_radios

 public static function get_all_radios($catalog = null)
 {
     $sql = "SELECT `live_stream`.`id` FROM `live_stream` JOIN `catalog` ON `catalog`.`id` = `live_stream`.`catalog` ";
     if (AmpConfig::get('catalog_disable')) {
         $sql .= "WHERE `catalog`.`enabled` = '1' ";
     }
     $params = array();
     if ($catalog) {
         if (AmpConfig::get('catalog_disable')) {
             $sql .= "AND ";
         }
         $sql .= "`catalog`.`id` = ?";
         $params[] = $catalog;
     }
     $db_results = Dba::read($sql, $params);
     $radios = array();
     while ($results = Dba::fetch_assoc($db_results)) {
         $radios[] = $results['id'];
     }
     return $radios;
 }
开发者ID:ivan801,项目名称:ampache,代码行数:21,代码来源:live_stream.class.php

示例12: sort_tracks

 /**
  * Sort the tracks and save the new position
  */
 public function sort_tracks()
 {
     /* First get all of the songs in order of their tracks */
     $sql = "SELECT A.`id`\n                FROM `playlist_data` AS A\n           LEFT JOIN `song` AS B ON A.object_id = B.id\n           LEFT JOIN `artist` AS C ON B.artist = C.id\n           LEFT JOIN `album` AS D ON B.album = D.id\n               WHERE A.`playlist` = ?\n            ORDER BY C.`name` ASC,\n                     B.`title` ASC,\n                     D.`year` ASC,\n                     D.`name` ASC,\n                     B.`track` ASC";
     $db_results = Dba::query($sql, array($this->id));
     $i = 1;
     $results = array();
     while ($r = Dba::fetch_assoc($db_results)) {
         $new_data = array();
         $new_data['id'] = $r['id'];
         $new_data['track'] = $i;
         $results[] = $new_data;
         $i++;
     }
     // end while results
     foreach ($results as $data) {
         $sql = "UPDATE `playlist_data` SET `track` = ? WHERE `id` = ?";
         Dba::write($sql, array($data['track'], $data['id']));
     }
     // foreach re-ordered results
     return true;
 }
开发者ID:nioc,项目名称:ampache,代码行数:25,代码来源:playlist.class.php

示例13: gc

 public static function gc()
 {
     $sql = 'DELETE FROM `song_preview` USING `song_preview` ' . 'LEFT JOIN `session` ON `session`.`id`=`song_preview`.`session` ' . 'WHERE `session`.`id` IS NULL';
     return Dba::write($sql);
 }
开发者ID:cheese1,项目名称:ampache,代码行数:5,代码来源:song_preview.class.php

示例14: mysql_auth

 /**
  * mysql_auth
  *
  * This is the core function of our built-in authentication.
  */
 private static function mysql_auth($username, $password)
 {
     if (strlen($password) && strlen($username)) {
         $sql = 'SELECT `password` FROM `user` WHERE `username` = ?';
         $db_results = Dba::read($sql, array($username));
         if ($row = Dba::fetch_assoc($db_results)) {
             // Use SHA2 now... cooking with fire.
             // For backwards compatibility we hash a couple of different
             // variations of the password. Increases collision chances, but
             // doesn't break things.
             // FIXME: Break things in the future.
             $hashed_password = array();
             $hashed_password[] = hash('sha256', $password);
             $hashed_password[] = hash('sha256', Dba::escape(stripslashes(htmlspecialchars(strip_tags($password)))));
             // Automagically update the password if it's old and busted.
             if ($row['password'] == $hashed_password[1] && $hashed_password[0] != $hashed_password[1]) {
                 $user = User::get_from_username($username);
                 $user->update_password($password);
             }
             if (in_array($row['password'], $hashed_password)) {
                 return array('success' => true, 'type' => 'mysql', 'username' => $username);
             }
         }
     }
     return array('success' => false, 'error' => 'MySQL login attempt failed');
 }
开发者ID:axelsimon,项目名称:ampache,代码行数:31,代码来源:auth.class.php

示例15: set_rating

 /**
  * set_rating
  * This function sets the rating for the current object.
  * If no userid is passed in, we use the currently logged in user.
  */
 public function set_rating($rating, $user_id = null)
 {
     if (is_null($user_id)) {
         $user_id = $GLOBALS['user']->id;
     }
     $user_id = intval($user_id);
     debug_event('Rating', "Setting rating for {$this->type} {$this->id} to {$rating}", 5);
     // If score is -1, then remove rating
     if ($rating == '-1') {
         $sql = "DELETE FROM `rating` WHERE " . "`object_id` = ? AND " . "`object_type` = ? AND " . "`user` = ?";
         $params = array($this->id, $this->type, $user_id);
     } else {
         $sql = "REPLACE INTO `rating` " . "(`object_id`, `object_type`, `rating`, `user`) " . "VALUES (?, ?, ?, ?)";
         $params = array($this->id, $this->type, $rating, $user_id);
     }
     Dba::write($sql, $params);
     parent::add_to_cache('rating_' . $this->type . '_user' . $user_id, $this->id, $rating);
     foreach (Plugin::get_plugins('save_rating') as $plugin_name) {
         $plugin = new Plugin($plugin_name);
         if ($plugin->load($GLOBALS['user'])) {
             $plugin->_plugin->save_rating($this, $rating);
         }
     }
     return true;
 }
开发者ID:axelsimon,项目名称:ampache,代码行数:30,代码来源:rating.class.php


注:本文中的Dba类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。