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


PHP get_db_link函数代码示例

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


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

示例1: search_init

/**
 * Initialize search plugin
 */
function search_init()
{
    global $CONFIG;
    require_once 'search_hooks.php';
    // page handler for search actions and results
    elgg_register_page_handler('search', 'search_page_handler');
    // register some default search hooks
    elgg_register_plugin_hook_handler('search', 'object', 'search_objects_hook');
    elgg_register_plugin_hook_handler('search', 'user', 'search_users_hook');
    elgg_register_plugin_hook_handler('search', 'group', 'search_groups_hook');
    // tags and comments are a bit different.
    // register a search types and a hooks for them.
    elgg_register_plugin_hook_handler('search_types', 'get_types', 'search_custom_types_tags_hook');
    elgg_register_plugin_hook_handler('search', 'tags', 'search_tags_hook');
    elgg_register_plugin_hook_handler('search_types', 'get_types', 'search_custom_types_comments_hook');
    elgg_register_plugin_hook_handler('search', 'comments', 'search_comments_hook');
    // get server min and max allowed chars for ft searching
    $CONFIG->search_info = array();
    // can't use get_data() here because some servers don't have these globals set,
    // which throws a db exception.
    $dblink = get_db_link('read');
    $r = mysql_query('SELECT @@ft_min_word_len as min, @@ft_max_word_len as max', $dblink);
    if ($r && ($word_lens = mysql_fetch_assoc($r))) {
        $CONFIG->search_info['min_chars'] = $word_lens['min'];
        $CONFIG->search_info['max_chars'] = $word_lens['max'];
    } else {
        // uhhh these are good numbers.
        $CONFIG->search_info['min_chars'] = 4;
        $CONFIG->search_info['max_chars'] = 90;
    }
    // add in CSS for search elements
    elgg_extend_view('css/elgg', 'search/css');
    // extend view for elgg topbar search box
    elgg_extend_view('page/elements/header', 'search/header');
}
开发者ID:nogsus,项目名称:Elgg,代码行数:38,代码来源:start.php

示例2: is_db_installed

/**
 * Returns whether or not the database has been installed
 *
 * @return true|false Whether the database has been installed
 */
function is_db_installed()
{
    global $CONFIG;
    if (isset($CONFIG->db_installed)) {
        return $CONFIG->db_installed;
    }
    if ($dblink = get_db_link('read')) {
        mysql_query("select name from {$CONFIG->dbprefix}datalists limit 1", $dblink);
        if (mysql_errno($dblink) > 0) {
            return false;
        }
    } else {
        return false;
    }
    $CONFIG->db_installed = true;
    // Set flag if db is installed (if false then we want to check every time)
    return true;
}
开发者ID:eokyere,项目名称:elgg,代码行数:23,代码来源:install.php

示例3: syncAnnotations

 public function syncAnnotations()
 {
     $dblink = get_db_link('read');
     $site = elgg_get_site_entity();
     $result = execute_query('SELECT COUNT(`id`) FROM elgg_annotations', $dblink);
     $row = mysqli_fetch_row($result);
     $total = (int) $row[0];
     $result = execute_query('SELECT `id` FROM elgg_annotations ORDER BY id', $dblink);
     while ($row = mysqli_fetch_row($result)) {
         $ids[] = $row[0];
         if (count($ids) == 50) {
             $this->processItems('annotations', $ids);
             $ids = array();
         }
         $i += 1;
         if ($i % 500 == 0) {
             echo round($i / $total * 100, 2) . "%\r";
         }
     }
     if (count($ids) > 0) {
         $this->processItems('annotations', $ids);
     }
 }
开发者ID:pleio,项目名称:elasticsearch,代码行数:23,代码来源:ESBulkSync.php

示例4: delete_data

/**
 * Remove a row from the database.
 *
 * @note Altering the DB invalidates all queries in {@link $DB_QUERY_CACHE}.
 *
 * @param string $query The SQL query to run
 *
 * @return int|false The number of affected rows or false on failure
 * @access private
 */
function delete_data($query)
{
    global $CONFIG, $DB_QUERY_CACHE;
    $query = elgg_format_query($query);
    elgg_log("DB query {$query}", 'NOTICE');
    $dblink = get_db_link('write');
    // Invalidate query cache
    if ($DB_QUERY_CACHE) {
        $DB_QUERY_CACHE->clear();
        elgg_log("Query cache invalidated", 'NOTICE');
    }
    if (execute_query("{$query}", $dblink)) {
        return mysql_affected_rows($dblink);
    }
    return FALSE;
}
开发者ID:nachopavon,项目名称:Elgg,代码行数:26,代码来源:database.php

示例5: test_db_shutdown_links

 function test_db_shutdown_links()
 {
     global $DB_DELAYED_QUERIES, $test_results;
     $DB_DELAYED_QUERIES = array();
     function test_delayed_results($results)
     {
         global $test_results;
         $test_results = $results;
     }
     $q = 'SELECT 1 as test';
     $links = array('read', 'write', get_db_link('read'), get_db_link('write'));
     foreach ($links as $link) {
         $DB_DELAYED_QUERIES = array();
         $result = execute_delayed_query($q, $link, 'test_delayed_results');
         $this->assertTrue($result, "Failed with link = {$link}");
         $this->assertEqual(count($DB_DELAYED_QUERIES), 1);
         $this->assertEqual($DB_DELAYED_QUERIES[0]['q'], $q);
         $this->assertEqual($DB_DELAYED_QUERIES[0]['l'], $link);
         $this->assertEqual($DB_DELAYED_QUERIES[0]['h'], 'test_delayed_results');
         db_delayedexecution_shutdown_hook();
         $num_rows = mysql_num_rows($test_results);
         $this->assertEqual($num_rows, 1);
         $row = mysql_fetch_assoc($test_results);
         $this->assertEqual($row['test'], 1);
     }
     // test bad case
     $DB_DELAYED_QUERIES = array();
     $result = execute_delayed_query($q, 'not_a_link', 'test_delayed_results');
     $this->assertFalse($result);
     $this->assertEqual(array(), $DB_DELAYED_QUERIES);
 }
开发者ID:duanhv,项目名称:mdg-social,代码行数:31,代码来源:trac_bugs.php

示例6: delete_data

/**
 * Use this function to delete data
 *
 * @param mixed $query The SQL query to run
 * @return int|false Either the number of affected rows, or false on failure
 */
function delete_data($query)
{
    global $CONFIG, $DB_QUERY_CACHE;
    $dblink = get_db_link('write');
    // Invalidate query cache
    if ($DB_QUERY_CACHE) {
        $DB_QUERY_CACHE->clear();
    }
    if (isset($CONFIG->debug) && $CONFIG->debug == true) {
        error_log("Query cache invalidated");
    }
    if (execute_query("{$query}", $dblink)) {
        return mysql_affected_rows($dblink);
    }
    return false;
}
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:22,代码来源:database.php

示例7: verify_installation

/**
 * Check that installation has completed and the database is populated.
 *
 * @throws InstallationException|DatabaseException
 * @return void
 * @access private
 */
function verify_installation()
{
    global $CONFIG;
    if (isset($CONFIG->installed)) {
        return;
    }
    try {
        $dblink = get_db_link('read');
        if (!$dblink) {
            throw new DatabaseException();
        }
        mysql_query("SELECT value FROM {$CONFIG->dbprefix}datalists WHERE name = 'installed'", $dblink);
        if (mysql_errno($dblink) > 0) {
            throw new DatabaseException();
        }
        $CONFIG->installed = true;
    } catch (DatabaseException $e) {
        throw new InstallationException(elgg_echo('InstallationException:SiteNotInstalled'));
    }
}
开发者ID:duanhv,项目名称:mdg-social,代码行数:27,代码来源:configuration.php

示例8: my_save_email

/**
 * Save mail callback
 * Accepts an email received from a client during the DATA command.
 * This email is processed, the recipient host is verified, the body is
 * decoded, then saved to the database.
 * This is an example save mail function.
 * Of course, yours can be better! Eg. add buffered writes, place email on message queue, encryption, etc
 *
 * @param string $email
 * @param        $rcpt_to
 * @param        $helo
 * @param        $helo_ip
 *
 * @return array, with the following elements array($hash, $recipient)
 * where the $hash is a unique id for this email.
 */
function my_save_email($email, $rcpt_to, $helo, $helo_ip)
{
    global $GM_ERROR;
    $mimemail = null;
    $hash = '';
    $email .= "\r\n";
    list($to, $from, $subject) = get_email_headers($email, array('To', 'From', 'Subject'));
    $rcpt_to = extract_rcpt_email($rcpt_to);
    $from = extract_email($from);
    list($mail_user, $mail_host) = explode('@', $rcpt_to);
    if (is_host_allowed($mail_host)) {
        $db = get_db_link();
        if ($db === false) {
            // could not get a db connection
            $GM_ERROR = 'could not get a db connection';
            return array(false, false);
        }
        $to = $mail_user . '@' . GM_PRIMARY_MAIL_HOST;
        // change it to the primary host
        if (GSMTP_VERIFY_USERS) {
            // Here we can verify that the recipient is actually in the database.
            // Note that guerrillamail.com does not do this - you can send email
            // to a non-existing email address, and set to this email later.
            // just an example:
            if (array_pop(explode('@', $to)) !== 'sharklasers.com') {
                // check the user against our user database
                $user = array_shift(explode('@', $to));
                $sql = "SELECT * FROM `gm2_address` WHERE `address_email`=" . $db->quote($user . '@guerrillamailblock.com') . " ";
                $stmt = $db->query($sql);
                if ($stmt->rowCount() == 0) {
                    $GM_ERROR = 'could not verify user';
                    return false;
                    // no such address
                }
            }
        }
        $hash = md5($to . $from . $subject . microtime());
        // add 'received' headers
        $add_head = '';
        $add_head .= "Delivered-To: " . $to . "\r\n";
        $add_head .= "Received: from " . $helo . " (" . $helo . "  [" . $helo_ip . "])\r\n";
        $add_head .= "\tby " . GSMTP_HOST_NAME . " with SMTP id " . $hash . "@" . GSMTP_HOST_NAME . ";\r\n";
        $add_head .= "\t" . gmdate('r') . "\r\n";
        $email = $add_head . $email;
        $body = 'gzencode';
        $charset = '';
        $has_attach = '';
        $content_type = '';
        $email = gzcompress($email, 6);
        $redis = getRedis();
        if (is_object($redis)) {
            // send it of to Redis
            try {
                if ($redis->setex($hash, 3600, $email) === true) {
                    $body = 'redis';
                    $email = '';
                    //log_line("saved to redis $hash $to");
                } else {
                    log_line("save failed");
                }
            } catch (\RedisException $e) {
                log_line("redis exeption" . var_dump($e, true));
            }
        } else {
            log_line("no redis for you\n");
        }
        $sql = "INSERT INTO " . GM_MAIL_TABLE . " (\n                `date`,\n                `to`,\n                `from`,\n                `subject`,\n                `body`,\n                `charset`,\n                `mail`,\n                `spam_score`,\n                `hash`,\n                `content_type`,\n                `recipient`,\n                `has_attach`,\n                `ip_addr`\n            )\n            VALUES (\n                '" . gmdate('Y-m-d H:i:s') . "',\n                " . $db->quote($to) . ",\n                " . $db->quote($from) . ",\n                " . $db->quote($subject) . ",\n                " . $db->quote($body) . ",\n                " . $db->quote($charset) . ",\n                " . $db->quote($email) . ",\n                0 " . ",\n                " . $db->quote($hash) . ",\n                " . $db->quote($content_type) . ",\n                " . $db->quote($to) . ",\n                " . $db->quote($has_attach) . ",\n                " . $db->quote($helo_ip) . "\n            ) ";
        try {
            $db->query($sql);
            $id = $db->lastInsertId();
            if ($id) {
                $sql = "UPDATE\n                            gm2_setting\n                       SET\n                            `setting_value` = `setting_value`+1\n                       WHERE\n                            `setting_name`='received_emails'\n                            LIMIT 1";
                $db->query($sql);
            }
        } catch (\PDOException $e) {
            $GM_ERROR = 'save error ' . $e->getMessage();
            log_line('Failed to save email From:' . $from . ' To:' . $to . ' ' . $e->getMessage() . ' ' . $sql, 1);
        }
    } else {
        $GM_ERROR = " -{$mail_host}- not in allowed hosts:" . $mail_host . " ";
    }
    return array($hash, $to);
}
开发者ID:myselfhimself,项目名称:Guerrilla-SMTPd,代码行数:99,代码来源:smtpd.php

示例9: delete_data

/**
 * Remove data from the database.
 *
 * @note Altering the DB invalidates all queries in {@link $DB_QUERY_CACHE}.
 *
 * @param string $query The SQL query to run
 *
 * @return int|false The number of affected rows or false on failure
 * @access private
 */
function delete_data($query)
{
    elgg_log("DB query {$query}", 'NOTICE');
    $dblink = get_db_link('write');
    _elgg_invalidate_query_cache();
    if (execute_query("{$query}", $dblink)) {
        return mysql_affected_rows($dblink);
    }
    return FALSE;
}
开发者ID:duanhv,项目名称:mdg-social,代码行数:20,代码来源:database.php

示例10: delete_data

/**
 * Remove a row from the database.
 *
 * @note Altering the DB invalidates all queries in {@link $DB_QUERY_CACHE}.
 *
 * @param string $query The SQL query to run
 *
 * @return int|false The number of affected rows or false on failure
 * @access private
 */
function delete_data($query)
{
    global $DB_QUERY_CACHE, $DB_QUERY_CACHE_COUNT;
    elgg_log("DB query {$query}", 'NOTICE');
    $dblink = get_db_link('write');
    // Invalidate query cache
    if ($DB_QUERY_CACHE) {
        /* @var ElggStaticVariableCache $DB_QUERY_CACHE */
        $DB_QUERY_CACHE->clear();
        $DB_QUERY_CACHE_COUNT = 0;
        elgg_log("Query cache invalidated", 'NOTICE');
    }
    if (execute_query("{$query}", $dblink)) {
        return mysql_affected_rows($dblink);
    }
    return FALSE;
}
开发者ID:pleio,项目名称:subsite_manager,代码行数:27,代码来源:database.php


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