Esempio n. 1
0
function db_connect()
{
    $config = db_config();
    $result = mysql_pconnect($config['host'], $config['user'], $config['password']);
    if (!$result) {
        return false;
    }
    if (!mysql_select_db($config['db'])) {
        return false;
    }
    return $result;
}
Esempio n. 2
0
function transaction(closure $action)
{
    $config = db_config();
    $connection = db_connection($config);
    $began = $connection->beginTransaction();
    if (!$began) {
        throw new Exception('can not start transaction');
    }
    try {
        $res = $action();
        $connection->commit();
        return $res;
    } catch (Exception $ex) {
        $connection->rollBack();
        throw $ex;
    }
}
Esempio n. 3
0
 protected static function initialization($cli = FALSE)
 {
     $hasFile = FALSE;
     //命令行模式,使用-c指定的配置文件
     if ($cli) {
         self::$options = getopt('c:f');
         if (isset(self::$options['c']) && is_file(self::$options['c'])) {
             require_once self::$options['c'];
             $hasFile = TRUE;
         }
     } else {
         foreach (self::$projects as $project => $val) {
             $file = $val['dir'] . '/config.php';
             if (is_file($file)) {
                 require_once $file;
                 $hasFile = TRUE;
                 break;
             }
         }
     }
     if (!$hasFile) {
         exit('Please set the config file.' . "\n");
     }
     //写到全局config对象
     isset($conf) && config()->set('conf', $conf);
     //设置数据库
     isset($conf['databases']) && db_config($conf['databases']);
     //设置缓存
     isset($conf['caches']) && cache_config($conf['caches']);
     //设置缓存
     isset($conf['loggers']) && logger_config($conf['loggers']);
 }
Esempio n. 4
0
#!/usr/bin/php
<?php 
require_once 'phplib/Sag.php';
require_once 'functions.php';
require_once 'config.php';
// check while
while ($stop == false) {
    while ($host == false) {
        foreach (explode(" ", $hosts) as $testhost) {
            $host = check_couchdb($testhost);
            if ($host) {
                break;
            }
        }
        if ($host) {
            continue;
        }
        do_log("No connect to cluster-db sleep now for next tray in (s):" . $testsleep);
        sleep($testsleep);
    }
    $sag = new Sag($host);
    $dbconfig = db_config();
    print_r($dbconfig->default->fs_nodes);
    sleep(5);
    $host = false;
}
function display()
{
    echo "\n    |--------------------------------------------------\n    | [Prodígio Framework]\n    | * Instruções:\n    | -------------------------------------------------\n    | Passo 1 - Crie um formulário HTML\n    | dentro da pasta [html_form_pages]\n    | e dê nome a todas as tags[OBRIGATÓRIO]\n    | -------------------------------------------------\n    | Passo 2 - Digite make-class para gerar\n    |  as classes conforme o formulairo\n    | criado em html_form_pages\n    | -------------------------------------------------\n    | Passo 3 - Acesse a pasta /generate_class/\n    | e veja as classes geradas.\n    | -------------------------------------------------\n    | Passo 4  - Configure o seu banco de\n    | dados, execute db-config e informe:\n    | *nome do banco de dados\n    | *usuário, senha e host.\n    | -------------------------------------------------\n    | Digite exit para sair..\n    |--------------------------------------------------\n    ";
}
$escolha = 0;
$html = file_get_contents(FORM_PAGES_PATH);
while (1) {
    display();
    $msg = "Aperte ";
    $escolha = readline("Digite aqui: ");
    switch ($escolha) {
        case 'make-class':
            make_class();
            break;
        case 'show':
            echo shell_exec("php project/sobre.php");
            break;
        case 'db-config':
            $database_name = readline("Digite o nome do banco de dados: ");
            $database_user = readline("Digite o nome do usuário do banco: ");
            $database_pass = readline("Digite a sua senha de banco de dados: ");
            $database_host = readline("Informe o hostname ex:[localhost]: ");
            db_config($database_name, $database_user, $database_pass, $database_host);
            break;
        case 'exit':
            exit;
            break;
    }
    readline("\n{$msg} [ENTER]");
    echo shell_exec("clear");
}
/**
 * Establish a new database connection to the MySQL server
 * @param string $namespace Namespace of the configuration.
 */
function db_connect($namespace = 'default')
{
    global $_conn;
    global $_DB;
    $conf = db_config($namespace);
    # Connection
    $_conn = mysqli_connect($conf['host'], $conf['username'], $conf['password']);
    if (!$_conn) {
        die('Not connected mysqli!');
    }
    # Force MySQL to use the UTF-8 character set. Also set the collation, if a certain one has been set;
    # otherwise, MySQL defaults to 'utf8_general_ci' # for UTF-8.
    if (!db_setCharset('utf8')) {
        printf("Error loading character set utf8: %s", mysqli_error($_conn));
    }
    if (db_collation()) {
        db_query('SET NAMES utf8 COLLATE ' . db_collation());
    }
    # Select DB
    if (!mysqli_select_db($_conn, $conf['database'])) {
        die('Can\'t use  : ' . $conf['database'] . ' - ' . mysqli_error($_conn));
    }
    $_DB = new stdClass();
    $_DB->name = $conf['database'];
    $_DB->namespace = $namespace;
    # Load the schema of the currently connected database
    $schema = _schema($namespace, true);
    $_DB->schemaManager = new SchemaManager($schema);
    if (!$_DB->schemaManager->isLoaded()) {
        $_DB->schemaManager->build($namespace);
    }
}
Esempio n. 7
0
<?php

// debug
ini_set("display_errors", "on");
// timezone
date_default_timezone_set('Asia/Shanghai');
// view path
view_path(__DIR__ . '/view/');
// db config
db_config();
Esempio n. 8
0
<?php

// init view path
view_path(__DIR__ . '/../view/');
db_config(array('host' => '127.0.0.1', 'username' => 'root', 'password' => '', 'database' => 'passwd'));
// init mongo config
mongo_config(array('database' => 'test'));
$GLOBALS['keys'] = "ADOCXLIE213WADACVTWE32`123";
// init 404 handler
if_not_found(function ($msg = '') {
    return render('notfound');
});
$GLOBALS['redisConfig'] = array('scheme' => 'tcp', 'host' => '127.0.0.1', 'port' => 6379);
$GLOBALS['redisCacheTime'] = 3600;