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


PHP dba_open函数代码示例

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


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

示例1: __construct

 public function __construct($database, $readonly = true, $useCache = true)
 {
     $this->useCache = $useCache;
     $file_exists = File::exists($database);
     if (!$file_exists) {
         $readonly = false;
     }
     if ($readonly) {
         $opt = 'rl';
         if (!is_readable($database)) {
             throw new Exception('database is not readable: ' . $database);
             return false;
         }
     } else {
         $opt = 'cl';
         if ($file_exists) {
             if (!is_writable($database)) {
                 throw new Exception('database is not writeable: ' . $database);
                 return false;
             }
         } else {
             if (!is_writable(dirname($database))) {
                 throw new Exception('database is not inside a writeable directory: ' . $database);
                 return false;
             }
         }
     }
     $this->dbHandler = dba_open($database, $opt, self::HANDLER);
     if (!$this->dbHandler) {
         throw new Exception('cannot open database: ' . $database);
         return false;
     }
     return $this;
 }
开发者ID:schpill,项目名称:thin,代码行数:34,代码来源:Dba.php

示例2: Indexer_dba

 function Indexer_dba($arena, $mode = 'r', $type, $prefix = '')
 {
     global $DBInfo;
     $this->index_dir = $DBInfo->cache_dir . '/index';
     if (!file_exists($this->index_dir)) {
         mkdir($this->index_dir, 0777);
     }
     $this->prefix = $prefix;
     if (!empty($prefix)) {
         $prefix = $prefix . '.';
     }
     $this->dbname = $this->index_dir . '/' . $prefix . $arena . '.db';
     $this->arena = $arena;
     // check updated db file.
     if (empty($prefix) and file_exists($this->index_dir . '/' . $arena . '.new.db')) {
         if (!file_exists($this->dbname) or filemtime($this->index_dir . '/' . $arena . '.new.db') > filemtime($this->dbname)) {
             @touch($this->dbname);
             $tmpname = '.tmp_' . time();
             copy($this->index_dir . '/' . $arena . '.new.db', $this->dbname . $tmpname);
             rename($this->dbname . $tmpname, $this->dbname);
         }
     }
     if (($this->db = @dba_open($this->dbname, $mode, $type)) === false) {
         if (($this->db = @dba_open($this->dbname, 'n', $type)) === false) {
             return false;
         }
         // startkey==256
         dba_insert("", 1, $this->db);
         dba_sync($this->db);
     }
     register_shutdown_function(array(&$this, 'close'));
     return true;
 }
开发者ID:ahastudio,项目名称:moniwiki,代码行数:33,代码来源:indexer.DBA.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: __construct

 /**
  * Constructs the backend.
  *
  * @access public
  * @param string $config
  */
 function __construct($config, &$degenerator)
 {
     # Pass the degenerator instance to this class
     $this->degenerator = $degenerator;
     # Validate the config items
     foreach ($config as $name => $value) {
         switch ($name) {
             case 'database':
             case 'handler':
                 $this->config[$name] = (string) $value;
                 break;
             default:
                 throw new Exception("b8_storage_dba: Unknown configuration key: \"{$name}\"");
         }
     }
     # Connect to the database
     $dbfile = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $this->config['database'];
     if (is_file($dbfile) !== TRUE) {
         throw new Exception("b8_storage_dba: Database file \"{$this->config['database']}\" not found.");
     }
     if (is_readable($dbfile) !== TRUE) {
         throw new Exception("b8_storage_dba: Database file \"{$this->config['database']}\" is not readable.");
     }
     if (is_writeable($dbfile) !== TRUE) {
         throw new Exception("b8_storage_dba: Database file \"{$this->config['database']}\" is not writeable.");
     }
     $this->_db = dba_open($dbfile, 'w', $this->config['handler']);
     if ($this->_db === FALSE) {
         $this->connected = FALSE;
         $this->_db = NULL;
         throw new Exception("b8_storage_dba: Could not connect to database file \"{$this->config['database']}\".");
     }
     # Let's see if this is a b8 database and the version is okay
     $this->check_database();
 }
开发者ID:bohwaz,项目名称:b8-backup,代码行数:41,代码来源:storage_dba.php

示例5: __construct

 function __construct()
 {
     $file = tempnam("/tmp", "");
     unlink($file);
     $this->_dir = "{$file}.db";
     $this->_db = dba_open($this->_dir, "c", "db4") or die("Unable to run reducer, please ensure you have dba + db4");
 }
开发者ID:rosarion,项目名称:php-hadoop,代码行数:7,代码来源:mem-file.php

示例6: getComments

function getComments($req)
{
    $err = "";
    $ra = array();
    $encoder = new PhpXmlRpc\Encoder();
    $msgID = $encoder->decode($req->getParam(0));
    $dbh = dba_open("/tmp/comments.db", "r", "db2");
    if ($dbh) {
        $countID = "{$msgID}_count";
        if (dba_exists($countID, $dbh)) {
            $count = dba_fetch($countID, $dbh);
            for ($i = 0; $i < $count; $i++) {
                $name = dba_fetch("{$msgID}_name_{$i}", $dbh);
                $comment = dba_fetch("{$msgID}_comment_{$i}", $dbh);
                // push a new struct onto the return array
                $ra[] = array("name" => $name, "comment" => $comment);
            }
        }
    }
    // 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($encoder->encode($ra));
    }
}
开发者ID:TsobuEnterprise,项目名称:phpxmlrpc,代码行数:27,代码来源:discuss.php

示例7: __construct

 public function __construct($database, $readonly = TRUE, $use_cache = TRUE)
 {
     $this->use_cache = $use_cache;
     $file_exists = file_exists($database);
     if (!$file_exists) {
         $readonly = FALSE;
     }
     if ($readonly) {
         $opt = 'rl';
         if (!is_readable($database)) {
             throw new Exception('database is not readable: ' . $database);
             return FALSE;
         }
     } else {
         $opt = 'cl';
         if ($file_exists) {
             if (!is_writable($database)) {
                 throw new Exception('database is not writeable: ' . $database);
                 return FALSE;
             }
         } else {
             if (!is_writable(dirname($database))) {
                 throw new Exception('database is not inside a writeable directory: ' . $database);
                 return FALSE;
             }
         }
     }
     $this->db_handler = dba_open($database, $opt, FlatFileDB::HANDLER);
     if (!$this->db_handler) {
         throw new Exception('cannot open database: ' . $database);
         return FALSE;
     }
     return $this;
 }
开发者ID:badpenguin,项目名称:flatfiledb,代码行数:34,代码来源:FlatFileDB.php

示例8: __construct

 public function __construct($fileName)
 {
     $this->handle = dba_open($fileName, 'r-', 'cdb');
     if (!$this->handle) {
         throw new Exception('Unable to open CDB file "' . $fileName . '"');
     }
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:7,代码来源:DBA.php

示例9: getcomments

function getcomments($m)
{
    global $xmlrpcerruser;
    $err = "";
    $ra = array();
    // get the first param
    if (XMLRPC_EPI_ENABLED == '1') {
        $msgID = xmlrpc_decode($m->getParam(0));
    } else {
        $msgID = php_xmlrpc_decode($m->getParam(0));
    }
    $dbh = dba_open("/tmp/comments.db", "r", "db2");
    if ($dbh) {
        $countID = "{$msgID}_count";
        if (dba_exists($countID, $dbh)) {
            $count = dba_fetch($countID, $dbh);
            for ($i = 0; $i < $count; $i++) {
                $name = dba_fetch("{$msgID}_name_{$i}", $dbh);
                $comment = dba_fetch("{$msgID}_comment_{$i}", $dbh);
                // push a new struct onto the return array
                $ra[] = array("name" => $name, "comment" => $comment);
            }
        }
    }
    // 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(php_xmlrpc_encode($ra));
    }
}
开发者ID:partisan-collective,项目名称:partisan,代码行数:33,代码来源:discuss.php

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

示例11: db4_destroy_create_new

function db4_destroy_create_new()
{
    $ret = $GLOBALS['db'] = dba_open(DATABASE_NAME, 'n', DATABASE_HANDLER);
    if ($ret === false) {
        die('failed to create database');
    }
    return $ret;
}
开发者ID:JasonWoof,项目名称:square,代码行数:8,代码来源:db.php

示例12: getWriter

 function getWriter()
 {
     $handle = dba_open($this->mFile, 'cl', $this->mHandler);
     if (!$handle) {
         wfDebug("Unable to open DBA cache file {$this->mFile}\n");
     }
     return $handle;
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:8,代码来源:DBABagOStuff.php

示例13: open

 function open($mode = 'w')
 {
     if ($this->_dbh) {
         return;
     }
     // already open.
     $watchdog = $this->_timeout;
     global $ErrorManager;
     $this->_dba_open_error = false;
     $ErrorManager->pushErrorHandler(new WikiMethodCb($this, '_dba_open_error_handler'));
     // oops, you don't have DBA support.
     if (!function_exists("dba_open")) {
         echo "You don't seem to have DBA support compiled into PHP.";
     }
     // lock supported since 4.3.0:
     if (check_php_version(4, 3, 0) and strlen($mode) == 1) {
         // PHP 4.3.x Windows lock bug workaround: http://bugs.php.net/bug.php?id=23975
         if (isWindows()) {
             $mode .= "-";
             // suppress locking, or
         } elseif ($this->_handler != 'gdbm') {
             // gdbm does it internally
             $mode .= "d";
             // else use internal locking
         }
     }
     while (($dbh = dba_open($this->_file, $mode, $this->_handler)) < 1) {
         if ($watchdog <= 0) {
             break;
         }
         flush();
         // "c" failed, try "w" instead.
         if (substr($mode, 0, 1) == "c" and file_exists($this->_file)) {
             $mode = "w";
         }
         // conflict: wait some random time to unlock (see ethernet)
         $secs = 0.5 + (double) rand(1, 32767) / 32767;
         sleep($secs);
         $watchdog -= $secs;
         if (strlen($mode) == 2) {
             $mode = substr($mode, 0, -1);
         }
     }
     $ErrorManager->popErrorHandler();
     if (!$dbh) {
         if ($error = $this->_dba_open_error) {
             $error->errno = E_USER_ERROR;
             $error->errstr .= "\nfile: " . $this->_file . "\nmode: " . $mode . "\nhandler: " . $this->_handler;
             $ErrorManager->handleError($error);
         } else {
             trigger_error("dba_open failed", E_USER_ERROR);
         }
     }
     $this->_dbh = $dbh;
     return !empty($dbh);
 }
开发者ID:pombredanne,项目名称:tuleap,代码行数:56,代码来源:DbaDatabase.php

示例14: recovery

 public function recovery($record)
 {
     $key = $record['key'];
     $store['value'] = $record['value'];
     $store['dateline'] = $record['dateline'];
     $store['ttl'] = $record['ttl'];
     $rs = dba_open(DATA_DIR . '/kvstore/dba.db', 'cl', $this->handle);
     $ret = dba_replace($this->create_key($key), serialize($store), $rs);
     dba_close($rs);
     return $ret;
 }
开发者ID:syjzwjj,项目名称:quyeba,代码行数:11,代码来源:dba.php

示例15: Open

 function Open($file, $mode = 'n')
 {
     $this->Close();
     $ext = substr(strrchr($file, '.'), 1);
     $ext = strtolower($ext);
     if ($ext == 'cdb' && $mode != 'r') {
         $ext = 'cdb_make';
     }
     $this->handler = dba_open($file, $mode, $ext);
     return $this->handler;
 }
开发者ID:lamphp,项目名称:scws,代码行数:11,代码来源:dba.class.php


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