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


PHP dba_insert函数代码示例

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


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

示例1: addcomment

function addcomment($m)
{
    global $xmlrpcerruser;
    $err = "";
    // get the first param
    $msgID = php_xmlrpc_decode($m->getParam(0));
    $name = php_xmlrpc_decode($m->getParam(1));
    $comment = php_xmlrpc_decode($m->getParam(2));
    $dbh = dba_open("/tmp/comments.db", "c", "db2");
    if ($dbh) {
        $countID = "{$msgID}_count";
        if (dba_exists($countID, $dbh)) {
            $count = dba_fetch($countID, $dbh);
        } else {
            $count = 0;
        }
        // add the new comment in
        dba_insert($msgID . "_comment_{$count}", $comment, $dbh);
        dba_insert($msgID . "_name_{$count}", $name, $dbh);
        $count++;
        dba_replace($countID, $count, $dbh);
        dba_close($dbh);
    } else {
        $err = "Unable to open comments database.";
    }
    // if we generated an error, create an error return response
    if ($err) {
        return new xmlrpcresp(0, $xmlrpcerruser, $err);
    } else {
        // otherwise, we create the right response
        // with the state name
        return new xmlrpcresp(new xmlrpcval($count, "int"));
    }
}
开发者ID:bitweaver,项目名称:xmlrpc_lib,代码行数:34,代码来源:discuss.php

示例2: insert

 /**
  * Store a key/value. If the key already exist : error
  *
  * @param string $key  the key
  * @param string $value
  *
  * @return boolean  false if failure
  */
 public function insert($key, $value)
 {
     if (is_resource($value)) {
         return false;
     }
     return dba_insert($key, serialize($value), $this->_connection);
 }
开发者ID:CREASIG,项目名称:lizmap-web-client,代码行数:15,代码来源:dba.kvdriver.php

示例3: run

 function run()
 {
     global $wgExtensionMessagesFiles, $wgMessageCache, $IP;
     $nameHash = md5(implode("\n", array_keys($wgExtensionMessagesFiles)));
     $dir = "{$IP}/cache/ext-msgs";
     wfMkdirParents($dir);
     $db = dba_open("{$dir}/{$nameHash}.cdb", 'n', 'cdb');
     if (!$db) {
         echo "Cannot open DB file\n";
         exit(1);
     }
     # Load extension messages
     foreach ($wgExtensionMessagesFiles as $file) {
         $messages = $magicWords = array();
         require $file;
         foreach ($messages as $lang => $unused) {
             $wgMessageCache->processMessagesArray($messages, $lang);
         }
     }
     # Write them to the file
     foreach ($wgMessageCache->mExtensionMessages as $lang => $messages) {
         foreach ($messages as $key => $text) {
             dba_insert("{$lang}:{$key}", $text, $db);
         }
     }
     dba_close($db);
 }
开发者ID:Jobava,项目名称:diacritice-meta-repo,代码行数:27,代码来源:makeMessageDB.php

示例4: add

 public function add($k, $v)
 {
     if (dba_exists($k, $this->handle)) {
         return FALSE;
     }
     return @dba_insert($k, $this->s->serialize($v), $this->handle);
 }
开发者ID:Gaia-Interactive,项目名称:gaia_core_php,代码行数:7,代码来源:dba.php

示例5: addComment

function addComment($req)
{
    $err = "";
    // since validation has already been carried out for us,
    // we know we got exactly 3 string values
    $encoder = new PhpXmlRpc\Encoder();
    $n = $encoder->decode($req);
    $msgID = $n[0];
    $name = $n[1];
    $comment = $n[2];
    $dbh = dba_open("/tmp/comments.db", "c", "db2");
    if ($dbh) {
        $countID = "{$msgID}_count";
        if (dba_exists($countID, $dbh)) {
            $count = dba_fetch($countID, $dbh);
        } else {
            $count = 0;
        }
        // add the new comment in
        dba_insert($msgID . "_comment_{$count}", $comment, $dbh);
        dba_insert($msgID . "_name_{$count}", $name, $dbh);
        $count++;
        dba_replace($countID, $count, $dbh);
        dba_close($dbh);
    } else {
        $err = "Unable to open comments database.";
    }
    // if we generated an error, create an error return response
    if ($err) {
        return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
    } else {
        // otherwise, we create the right response
        return new PhpXmlRpc\Response(new PhpXmlRpc\Value($count, "int"));
    }
}
开发者ID:TsobuEnterprise,项目名称:phpxmlrpc,代码行数:35,代码来源:discuss.php

示例6: buildPathCache

 function buildPathCache($paths, $last, $cwd, $zcache)
 {
     $parentPaths = array();
     $populated = array();
     $old_db_line = false;
     if (file_exists($cwd . '.patchwork.paths.txt')) {
         $old_db = @fopen($cwd . '.patchwork.paths.txt', 'rb');
         $old_db && ($old_db_line = fgets($old_db));
     } else {
         $old_db = false;
     }
     $tmp = $cwd . '.~' . uniqid(mt_rand(), true);
     $db = fopen($tmp, 'wb');
     $paths = array_flip($paths);
     unset($paths[$cwd]);
     uksort($paths, array($this, 'dirCmp'));
     foreach ($paths as $h => $level) {
         $this->populatePathCache($populated, $old_db, $old_db_line, $db, $parentPaths, $paths, substr($h, 0, -1), $level, $last);
     }
     $db && fclose($db);
     $old_db && fclose($old_db);
     $h = $cwd . '.patchwork.paths.txt';
     '\\' === DIRECTORY_SEPARATOR && file_exists($h) && @unlink($h);
     rename($tmp, $h) || unlink($tmp);
     if (function_exists('dba_handlers')) {
         $h = array('cdb', 'db2', 'db3', 'db4', 'qdbm', 'gdbm', 'ndbm', 'dbm', 'flatfile', 'inifile');
         $h = array_intersect($h, dba_handlers());
         $h || ($h = dba_handlers());
         if ($h) {
             foreach ($h as $db) {
                 if ($h = @dba_open($tmp, 'nd', $db, 0600)) {
                     break;
                 }
             }
         }
     } else {
         $h = false;
     }
     if ($h) {
         foreach ($parentPaths as $paths => &$level) {
             sort($level);
             dba_insert($paths, implode(',', $level), $h);
         }
         dba_close($h);
         $h = $cwd . '.patchwork.paths.db';
         '\\' === DIRECTORY_SEPARATOR && file_exists($h) && @unlink($h);
         rename($tmp, $h) || unlink($tmp);
     } else {
         $db = false;
         foreach ($parentPaths as $paths => &$level) {
             sort($level);
             $paths = md5($paths) . '.' . substr(md5($cwd), -6) . '.path.txt';
             $h = $zcache . $paths[0] . DIRECTORY_SEPARATOR . $paths[1] . DIRECTORY_SEPARATOR;
             file_exists($h) || mkdir($h, 0700, true);
             file_put_contents($h . $paths, implode(',', $level));
         }
     }
     return $db;
 }
开发者ID:nicolas-grekas,项目名称:Patchwork-sandbox,代码行数:59,代码来源:Updatedb.php

示例7: new_token

 function new_token($consumer, $type="request") {/*{{{*/
   $key = md5(time());
   $secret = time() + time();
   $token = new OAuthToken($key, md5(md5($secret)));
   if (!dba_insert("${type}_$key", serialize($token), $this->dbh)) {
     throw new OAuthException("doooom!");
   }
   return $token;
 }/*}}}*/
开发者ID:networksoft,项目名称:seekerplus2.com,代码行数:9,代码来源:SimpleOAuthDataStore.php

示例8: db4_insert

function db4_insert($key, $val)
{
    $binkey = bin4($key);
    dbg_log("inserting key #{$key} in binary that's ({$binkey})");
    $ret = dba_insert(bin4($key), $val, $GLOBALS['db']);
    if ($ret === false) {
        die('failed to insert');
    }
    return $ret;
}
开发者ID:JasonWoof,项目名称:square,代码行数:10,代码来源:db.php

示例9: newToken

 function newToken($consumer, $type = "request")
 {
     $key = md5(time());
     $secret = time() + time();
     $token = new \OAuth\Token($key, md5(md5($secret)));
     if (!dba_insert("{$type}_{$key}", serialize($token), $this->dbh)) {
         throw new \OAuth\Exception("doooom!");
     }
     return $token;
 }
开发者ID:nicokaiser,项目名称:php-oauth,代码行数:10,代码来源:SimpleOAuthDataStore.php

示例10: set

 public function set($key, $value)
 {
     // Store
     if ($this->useCache) {
         $this->cache[$key] = $value;
     }
     // Convert
     $v = $this->encode($value);
     // Write
     if (dba_exists($key, $this->dbHandler)) {
         $r = dba_replace($key, $v, $this->dbHandler);
     } else {
         $r = dba_insert($key, $v, $this->dbHandler);
     }
     return $r;
 }
开发者ID:schpill,项目名称:thin,代码行数:16,代码来源:Dba.php

示例11: WRITE

 function WRITE($hash, $overwrite = 0)
 {
     $key = $hash["id"] . "." . $hash["version"];
     $ex = dba_exists($key, $this->handle);
     if (!$overwrite && $ex) {
         return;
     }
     $hash = serialize($hash);
     if ($this->gz) {
         $hash = gzcompress($hash, $this->gz);
     }
     if ($ex) {
         $r = dba_replace($key, $hash, $this->handle);
     } else {
         $r = dba_insert($key, $hash, $this->handle);
     }
     return $r;
 }
开发者ID:gpuenteallott,项目名称:rox,代码行数:18,代码来源:dba.php

示例12: _swap

 private function _swap()
 {
     $count =& $this->_count;
     $disk =& $this->_disk;
     /* freeing memory and dump it to disk  {{{ */
     $limit = $this->_limit;
     if (memory_get_usage() / (1024 * 1024) <= $limit) {
         return;
         /* nothing to free-up, so return */
     }
     $limit -= $this->_threshold;
     /* dump X megabytes to disk */
     $wdata =& $this->_data;
     end($wdata);
     fwrite(STDERR, "Freeing " . ceil(memory_get_usage() / (1024 * 1024)) . "M " . time() . "\n");
     $i = $count;
     while (memory_get_usage() / (1024 * 1024) >= $limit) {
         if (--$i < 0) {
             break;
         }
         $xdata = current($wdata);
         if (!is_array($xdata)) {
             prev($wdata);
             continue;
         }
         $xkey = key($wdata);
         fwrite(STDERR, "\t\tAttempt to free {$xkey}\n");
         $serial = serialize($xdata);
         if (!dba_insert($xkey, $serial, $this->_db)) {
             dba_replace($xkey, $serial, $this->_db);
         }
         unset($wdata[$xkey]);
         unset($xdata);
         unset($serial);
         $wdata[$xkey] = true;
         prev($wdata);
         $disk++;
     }
     dba_sync($this->_db);
     fwrite(STDERR, "\tFreed " . ceil(memory_get_usage() / (1024 * 1024)) . "M " . time() . "\n");
     /* }}} */
 }
开发者ID:rosarion,项目名称:php-hadoop,代码行数:42,代码来源:mem-file.php

示例13: addcomment

function addcomment($m)
{
    global $xmlrpcerruser;
    $err = "";
    // since validation has already been carried out for us,
    // we know we got exactly 3 string values
    $n = php_xmlrpc_decode($m);
    $msgID = $n[0];
    $name = $n[1];
    $comment = $n[2];
    $dbh = dba_open("/tmp/comments.db", "c", "db2");
    if ($dbh) {
        $countID = "{$msgID}_count";
        if (dba_exists($countID, $dbh)) {
            $count = dba_fetch($countID, $dbh);
        } else {
            $count = 0;
        }
        // add the new comment in
        dba_insert($msgID . "_comment_{$count}", $comment, $dbh);
        dba_insert($msgID . "_name_{$count}", $name, $dbh);
        $count++;
        dba_replace($countID, $count, $dbh);
        dba_close($dbh);
    } else {
        $err = "Unable to open comments database.";
    }
    // if we generated an error, create an error return response
    if ($err) {
        return new xmlrpcresp(0, $xmlrpcerruser, $err);
    } else {
        // otherwise, we create the right response
        // with the state name
        return new xmlrpcresp(new xmlrpcval($count, "int"));
    }
}
开发者ID:partisan-collective,项目名称:partisan,代码行数:36,代码来源:discuss.php

示例14: analyze

 function analyze($filename)
 {
     if (file_exists($filename)) {
         // Calc key     filename::mod_time::size    - should be unique
         $key = $filename . '::' . filemtime($filename) . '::' . filesize($filename);
         // Loopup key
         $result = dba_fetch($key, $this->dba);
         // Hit
         if ($result !== false) {
             return unserialize($result);
         }
     }
     // Miss
     $result = parent::analyze($filename);
     // Save result
     if (file_exists($filename)) {
         dba_insert($key, serialize($result), $this->dba);
     }
     return $result;
 }
开发者ID:Jayriq,项目名称:mmslides,代码行数:20,代码来源:extension.cache.dbm.php

示例15: dirname

<?php

require_once dirname(__FILE__) . '/test.inc';
echo "database handler: {$handler}\n";
if (($db_file = dba_open($db_file, "n", $handler)) !== FALSE) {
    dba_insert(array("a", "b", "c"), "Content String 2", $db_file);
} else {
    echo "Error creating database\n";
}
开发者ID:zaky-92,项目名称:php-1,代码行数:9,代码来源:ext_dba_tests_dba014.php


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