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


PHP Dba::disconnect方法代码示例

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


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

示例1: fread

        // This to avoid hang, see http://php.net/manual/es/function.proc-open.php#89338
        $transcode_error = fread($transcoder['stderr'], 4096);
        if (!empty($transcode_error)) {
            debug_event('play', 'Transcode stderr: ' . $transcode_error, 1);
        }
        fclose($transcoder['stderr']);
    }
}
// If this is a democratic playlist remove the entry.
// We do this regardless of play amount.
if ($demo_id && isset($democratic)) {
    $democratic->delete_from_oid($oid, $type);
}
// Close sql connection
// Warning: do not call functions requiring sql after this point
Dba::disconnect();
// Free the session write lock
// Warning: Do not change any session variable after this call
session_write_close();
$browser->downloadHeaders($media_name, $mime, false, $stream_size);
$bytes_streamed = 0;
// Actually do the streaming
$buf_all = '';
$r_arr = array($fp);
$w_arr = $e_arr = null;
$status = stream_select($r_arr, $w_arr, $e_arr, 2);
if ($status === false) {
    debug_event('play', 'stream_select failed.', 1);
} elseif ($status > 0) {
    do {
        $read_size = $transcode ? 2048 : min(2048, $stream_size - $bytes_streamed);
开发者ID:ivan801,项目名称:ampache,代码行数:31,代码来源:index.php

示例2: install_insert_db

/**
 * install_insert_db
 *
 * Inserts the database using the values from Config.
 */
function install_insert_db($db_user = null, $db_pass = null, $create_db = true, $overwrite = false, $create_tables = true)
{
    $database = AmpConfig::get('database_name');
    // Make sure that the database name is valid
    preg_match('/([^\\d\\w\\_\\-])/', $database, $matches);
    if (count($matches)) {
        Error::add('general', T_('Error: Invalid database name.'));
        return false;
    }
    if (!Dba::check_database()) {
        Error::add('general', sprintf(T_('Error: Unable to make database connection: %s'), Dba::error()));
        return false;
    }
    $db_exists = Dba::read('SHOW TABLES');
    if ($db_exists && $create_db) {
        if ($overwrite) {
            Dba::write('DROP DATABASE `' . $database . '`');
        } else {
            Error::add('general', T_('Error: Database already exists and overwrite not checked'));
            return false;
        }
    }
    if ($create_db) {
        if (!Dba::write('CREATE DATABASE `' . $database . '`')) {
            Error::add('general', sprintf(T_('Error: Unable to create database: %s'), Dba::error()));
            return false;
        }
    }
    Dba::disconnect();
    // Check to see if we should create a user here
    if (strlen($db_user) && strlen($db_pass)) {
        $db_host = AmpConfig::get('database_hostname');
        $sql = 'GRANT ALL PRIVILEGES ON `' . Dba::escape($database) . '`.* TO ' . "'" . Dba::escape($db_user) . "'";
        if ($db_host == 'localhost' || strpos($db_host, '/') === 0) {
            $sql .= "@'localhost'";
        }
        $sql .= "IDENTIFIED BY '" . Dba::escape($db_pass) . "' WITH GRANT OPTION";
        if (!Dba::write($sql)) {
            Error::add('general', sprintf(T_('Error: Unable to create user %1$s with permissions to %2$s on %3$s: %4$s'), $db_user, $database, $db_host, Dba::error()));
            return false;
        }
    }
    // end if we are creating a user
    if ($create_tables) {
        $sql_file = AmpConfig::get('prefix') . '/sql/ampache.sql';
        $query = fread(fopen($sql_file, 'r'), filesize($sql_file));
        $pieces = split_sql($query);
        $errors = array();
        for ($i = 0; $i < count($pieces); $i++) {
            $pieces[$i] = trim($pieces[$i]);
            if (!empty($pieces[$i]) && $pieces[$i] != '#') {
                if (!($result = Dba::write($pieces[$i]))) {
                    $errors[] = array(Dba::error(), $pieces[$i]);
                }
            }
        }
    }
    if ($create_db) {
        $sql = 'ALTER DATABASE `' . $database . '` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci';
        Dba::write($sql);
    }
    // If they've picked something other than English update default preferences
    if (AmpConfig::get('lang') != 'en_US') {
        // FIXME: 31? I hate magic.
        $sql = 'UPDATE `preference` SET `value`= ? WHERE `id` = 31';
        Dba::write($sql, array(AmpConfig::get('lang')));
        $sql = 'UPDATE `user_preference` SET `value` = ? WHERE `preference` = 31';
        Dba::write($sql, array(AmpConfig::get('lang')));
    }
    return true;
}
开发者ID:nioc,项目名称:ampache,代码行数:76,代码来源:install.lib.php


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