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


PHP Dba::fetch_assoc方法代码示例

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


在下文中一共展示了Dba::fetch_assoc方法的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: update_preferences

function update_preferences($pref_id = 0)
{
    /* Get current keys */
    $sql = "SELECT `id`,`name`,`type` FROM `preference`";
    /* If it isn't the System Account's preferences */
    if ($pref_id != '-1') {
        $sql .= " WHERE `catagory` != 'system'";
    }
    $db_results = Dba::read($sql);
    $results = array();
    // Collect the current possible keys
    while ($r = Dba::fetch_assoc($db_results)) {
        $results[] = array('id' => $r['id'], 'name' => $r['name'], 'type' => $r['type']);
    }
    // end collecting keys
    /* Foreach through possible keys and assign them */
    foreach ($results as $data) {
        /* Get the Value from POST/GET var called $data */
        $name = $data['name'];
        $apply_to_all = 'check_' . $data['name'];
        $new_level = 'level_' . $data['name'];
        $id = $data['id'];
        $value = scrub_in($_REQUEST[$name]);
        /* Some preferences require some extra checks to be performed */
        switch ($name) {
            case 'transcode_bitrate':
                $value = Stream::validate_bitrate($value);
                break;
            default:
                break;
        }
        if (preg_match('/_pass$/', $name)) {
            if ($value == '******') {
                unset($_REQUEST[$name]);
            } else {
                if (preg_match('/md5_pass$/', $name)) {
                    $value = md5($value);
                }
            }
        }
        /* Run the update for this preference only if it's set */
        if (isset($_REQUEST[$name])) {
            Preference::update($id, $pref_id, $value, $_REQUEST[$apply_to_all]);
        }
        if (Access::check('interface', '100') && $_REQUEST[$new_level]) {
            Preference::update_level($id, $_REQUEST[$new_level]);
        }
    }
    // end foreach preferences
    // Now that we've done that we need to invalidate the cached preverences
    Preference::clear_from_session();
}
开发者ID:cheese1,项目名称:ampache,代码行数:52,代码来源:preferences.php

示例3: 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

示例4: __construct

 /**
  * Stream_Playlist constructor
  * If an ID is passed, it should be a stream session ID.
  */
 public function __construct($id = null)
 {
     if ($id != -1) {
         if ($id) {
             Stream::set_session($id);
         }
         $this->id = Stream::$session;
         if (!Session::exists('stream', $this->id)) {
             debug_event('stream_playlist', 'Session::exists failed', 2);
             return false;
         }
         $this->user = intval($GLOBALS['user']->id);
         $sql = 'SELECT * FROM `stream_playlist` WHERE `sid` = ? ORDER BY `id`';
         $db_results = Dba::read($sql, array($this->id));
         while ($row = Dba::fetch_assoc($db_results)) {
             $this->urls[] = new Stream_URL($row);
         }
     }
     return true;
 }
开发者ID:axelsimon,项目名称:ampache,代码行数:24,代码来源:stream_playlist.class.php

示例5: 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

示例6: update_360020

 /**
  * update_360020
  *
  * Catalog types are plugins now
  */
 public static function update_360020()
 {
     $retval = true;
     $sql = "SELECT `id`, `catalog_type`, `path`, `remote_username`, `remote_password` FROM `catalog`";
     $db_results = Dba::read($sql);
     $c = Catalog::create_catalog_type('local');
     $c->install();
     $c = Catalog::create_catalog_type('remote');
     $c->install();
     while ($results = Dba::fetch_assoc($db_results)) {
         if ($results['catalog_type'] == 'local') {
             $sql = "INSERT INTO `catalog_local` (`path`, `catalog_id`) VALUES (?, ?)";
             $retval &= Dba::write($sql, array($results['path'], $results['id']));
         } elseif ($results['catalog_type'] == 'remote') {
             $sql = "INSERT INTO `catalog_remote` (`uri`, `username`, `password`, `catalog_id`) VALUES (?, ?, ?, ?)";
             $retval &= Dba::write($sql, array($results['path'], $results['remote_username'], $results['remote_password'], $results['id']));
         }
     }
     $sql = "ALTER TABLE `catalog` DROP `path`, DROP `remote_username`, DROP `remote_password`";
     $retval &= Dba::write($sql);
     $sql = "ALTER TABLE `catalog` MODIFY COLUMN `catalog_type` varchar(128)";
     $retval &= Dba::write($sql);
     $sql = "UPDATE `artist` SET `mbid` = null WHERE `mbid` = ''";
     $retval &= Dba::write($sql);
     $sql = "UPDATE `album` SET `mbid` = null WHERE `mbid` = ''";
     $retval &= Dba::write($sql);
     $sql = "UPDATE `song` SET `mbid` = null WHERE `mbid` = ''";
     $retval &= Dba::write($sql);
     return $retval;
 }
开发者ID:bl00m,项目名称:ampache,代码行数:35,代码来源:update.class.php

示例7: check

 /**
  * check
  *
  * Checks for an existing tv show; if none exists, insert one.
  */
 public static function check($name, $year, $tvshow_summary, $readonly = false)
 {
     // null because we don't have any unique id like mbid for now
     if (isset(self::$_mapcache[$name]['null'])) {
         return self::$_mapcache[$name]['null'];
     }
     $id = 0;
     $exists = false;
     $trimmed = Catalog::trim_prefix(trim($name));
     $name = $trimmed['string'];
     $prefix = $trimmed['prefix'];
     if (!$exists) {
         $sql = 'SELECT `id` FROM `tvshow` WHERE `name` LIKE ? AND `year` = ?';
         $db_results = Dba::read($sql, array($name, $year));
         $id_array = array();
         while ($row = Dba::fetch_assoc($db_results)) {
             $key = 'null';
             $id_array[$key] = $row['id'];
         }
         if (count($id_array)) {
             $id = array_shift($id_array);
             $exists = true;
         }
     }
     if ($exists) {
         self::$_mapcache[$name]['null'] = $id;
         return $id;
     }
     if ($readonly) {
         return null;
     }
     $sql = 'INSERT INTO `tvshow` (`name`, `prefix`, `year`, `summary`) VALUES(?, ?, ?, ?)';
     $db_results = Dba::write($sql, array($name, $prefix, $year, $tvshow_summary));
     if (!$db_results) {
         return null;
     }
     $id = Dba::insert_id();
     self::$_mapcache[$name]['null'] = $id;
     return $id;
 }
开发者ID:bl00m,项目名称:ampache,代码行数:45,代码来源:tvshow.class.php

示例8: show_playlist_select

/**
 * show_playlist_select
 * This one is for playlists!
 */
function show_playlist_select($name, $selected = '', $style = '')
{
    echo "<select name=\"{$name}\" style=\"{$style}\">\n";
    echo "\t<option value=\"\">" . T_('None') . "</option>\n";
    $sql = "SELECT `id`,`name` FROM `playlist` ORDER BY `name`";
    $db_results = Dba::read($sql);
    $nb_items = Dba::num_rows($db_results);
    $index = 1;
    $already_selected = false;
    while ($row = Dba::fetch_assoc($db_results)) {
        $select_txt = '';
        if (!$already_selected && ($row['id'] == $selected || $index == $nb_items)) {
            $select_txt = 'selected="selected"';
            $already_selected = true;
        }
        echo "\t<option value=\"" . $row['id'] . "\" {$select_txt}>" . scrub_out($row['name']) . "</option>\n";
        ++$index;
    }
    // end while users
    echo "</select>\n";
}
开发者ID:cheese1,项目名称:ampache,代码行数:25,代码来源:ui.lib.php

示例9: _clean_chunk

 /**
  * _clean_chunk
  * This is the clean function, its broken into
  * said chunks to try to save a little memory
  */
 private function _clean_chunk($media_type, $chunk, $chunk_size)
 {
     debug_event('clean', "Starting chunk {$chunk}", 5);
     $dead = array();
     $count = $chunk * $chunk_size;
     $sql = "SELECT `id`, `file` FROM `{$media_type}` " . "WHERE `catalog`='{$this->id}' LIMIT {$count},{$chunk_size}";
     $db_results = Dba::read($sql);
     while ($results = Dba::fetch_assoc($db_results)) {
         debug_event('clean', 'Starting work on ' . $results['file'] . '(' . $results['id'] . ')', 5);
         $count++;
         if (UI::check_ticker()) {
             $file = str_replace(array('(', ')', '\''), '', $results['file']);
             UI::update_text('clean_count_' . $this->id, $count);
             UI::update_text('clean_dir_' . $this->id, scrub_out($file));
         }
         $file_info = Core::get_filesize(Core::conv_lc_file($results['file']));
         if (!file_exists(Core::conv_lc_file($results['file'])) || $file_info < 1) {
             debug_event('clean', 'File not found or empty: ' . $results['file'], 5);
             AmpError::add('general', sprintf(T_('Error File Not Found or 0 Bytes: %s'), $results['file']));
             // Store it in an array we'll delete it later...
             $dead[] = $results['id'];
         } else {
             if (!Core::is_readable(Core::conv_lc_file($results['file']))) {
                 debug_event('clean', $results['file'] . ' is not readable, but does exist', 1);
             }
         }
     }
     return $dead;
 }
开发者ID:cheese1,项目名称:ampache,代码行数:34,代码来源:local.catalog.php

示例10: 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

示例11: get_song_previews

 public static function get_song_previews($album_mbid)
 {
     $songs = array();
     $sql = "SELECT `id` FROM `song_preview` " . "WHERE `session` = ? AND `album_mbid` = ?";
     $db_results = Dba::read($sql, array(session_id(), $album_mbid));
     while ($results = Dba::fetch_assoc($db_results)) {
         $songs[] = new Song_Preview($results['id']);
     }
     return $songs;
 }
开发者ID:cheese1,项目名称:ampache,代码行数:10,代码来源:song_preview.class.php

示例12: 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

示例13: 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

示例14: get_user

 /**
  * get_user
  * This gets all stats for atype based on user with thresholds and all
  * If full is passed, doesn't limit based on date
  */
 public static function get_user($count, $type, $user, $full = '')
 {
     $count = intval($count);
     $type = self::validate_type($type);
     /* If full then don't limit on date */
     if ($full) {
         $date = '0';
     } else {
         $date = time() - 86400 * AmpConfig::get('stats_threshold');
     }
     /* Select Objects based on user */
     //FIXME:: Requires table scan, look at improving
     $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" . " WHERE object_type = ? AND date >= ? AND user = ?" . " GROUP BY object_id ORDER BY `count` DESC LIMIT {$count}";
     $db_results = Dba::read($sql, array($type, $date, $user));
     $results = array();
     while ($r = Dba::fetch_assoc($db_results)) {
         $results[] = $r;
     }
     return $results;
 }
开发者ID:axelsimon,项目名称:ampache,代码行数:25,代码来源:stats.class.php

示例15: get_shares

 public static function get_shares($object_type, $object_id)
 {
     $sql = "SELECT `id` FROM `share` WHERE `object_type` = ? AND `object_id` = ?";
     $db_results = Dba::read($sql, array($object_type, $object_id));
     $results = array();
     while ($row = Dba::fetch_assoc($db_results)) {
         $results[] = $row['id'];
     }
     return $results;
 }
开发者ID:cheese1,项目名称:ampache,代码行数:10,代码来源:share.class.php


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