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


PHP MDB2::factory方法代码示例

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


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

示例1: Klutz_Driver_sql

 /**
  * Constructs a new SQL storage object.
  *
  * @param array $params  A hash containing connection parameters.
  */
 function Klutz_Driver_sql($params = array())
 {
     if (empty($params['basedir'])) {
         return null;
     }
     $this->basedir = $params['basedir'];
     if (substr($this->basedir, -1, 1) != "/") {
         $this->basedir .= "/";
     }
     /* Setup the database */
     $config = $GLOBALS['conf']['sql'];
     unset($config['charset']);
     $this->_db = MDB2::factory($config);
     $this->_db->setOption('seqcol_name', 'id');
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:20,代码来源:Sql.php

示例2: db_init

function db_init($user, $passwd, $host, $database, $die_on_error = TRUE, $charset = "UTF8")
{
    global $db;
    // DSN string must have new_link=true in order for multiple connections with different charsets to work
    $dsn = "mysql://{$user}:{$passwd}@{$host}/{$database}?new_link=true";
    $db = MDB2::factory($dsn);
    if (PEAR::isError($db)) {
        $msg = "Unable to initialise database. Please try again later.";
        $msg = "{$msg}: {$db->message} . ' ' . {$db->userinfo}";
        $db = NULL;
        db_log(1, $msg);
        if ($die_on_error) {
            if (defined('UNIT_TEST')) {
                print $msg . "\n";
            }
            exit;
        }
    } else {
        $db->setCharset($charset);
        // remove MDB2_PORTABILITY_EMPTY_TO_NULL - Without turning this setting off, MDB2 will treat empty strings (i.e. '')
        // as NULLs when storing. We prefer to use empty strings for some fields.
        // remove MDB2_PORTABILITY_FIX_CASE - keep associative fields case sensitive rather than all lower case
        $db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL ^ MDB2_PORTABILITY_FIX_CASE);
    }
}
开发者ID:bufvc,项目名称:bufvc-potnia-framework,代码行数:25,代码来源:database.inc.php

示例3: connect

 /**
  * connect()
  *
  * @access public
  * @param  string $sDsn
  * @param  mixed  $mOptions boolean | array
  * @return mixed            boolean | MDB2_Error
  */
 function connect($sDsn, $mOptions = array())
 {
     if (isset($this->_aryConn[$sDsn])) {
         $mRet = $this->setOptions($sDsn, $mOptions);
         if (MDB2::isError($mRet)) {
             return $mRet;
         }
         $this->_aryConn[$sDsn]->debug_output = '';
         return true;
     }
     if (!is_array($mOptions)) {
         $mOptions = array('persistent' => $mOptions);
     }
     $this->_aryConn[$sDsn] = MDB2::factory($sDsn, $mOptions);
     if (MDB2::isError($this->_aryConn[$sDsn])) {
         $objConn = $this->_aryConn[$sDsn];
         unset($this->_aryConn[$sDsn]);
         return $objConn;
     }
     $this->_aryConn[$sDsn]->loadModule('Date');
     $this->_aryConn[$sDsn]->loadModule('Extended');
     $this->_aryConn[$sDsn]->setFetchMode(MDB2_FETCHMODE_ASSOC);
     $this->_aryConn[$sDsn]->setCharset('UTF8');
     $this->_aryConn[$sDsn]->debug_output = '';
     return true;
 }
开发者ID:syttru,项目名称:blocken-test,代码行数:34,代码来源:BlockenDB.class.php

示例4: createInstance

 public function createInstance()
 {
     require_once 'MDB2.php';
     $dsn = $this->settings['db.dsn'];
     $db = MDB2::factory($dsn);
     return $db;
 }
开发者ID:manachyn,项目名称:trainings,代码行数:7,代码来源:AbstractFactory2.php

示例5: conectar

function conectar()
{
    if (!isset($mdb2)) {
        //Local
        $db_name = 'root';
        $db_password = '';
        $db_server = 'localhost';
        $db_database = 'coopcrucial';
        //Nabica
        /*$db_name = 'coopcrucial';
          $db_password = 'Nabica2012';
          $db_server = 'coopcrucial.db.5840507.hostedresource.com';
          $db_database = 'coopcrucial';*/
        $dsn = 'mysql://' . $db_name . ':' . $db_password . '@' . $db_server . '/' . $db_database;
        try {
            $mdb2 =& MDB2::factory($dsn, true);
            if (MDB2::isError($mdb2)) {
                die($mdb2->getmessage() . ' - ' . $mdb2->getUserInfo());
            } else {
                $mdb2->setFetchMode(MDB2_FETCHMODE_ASSOC);
            }
            $mdb2 = array('mdb2' => $mdb2, 'dsn' => $dsn);
        } catch (Exception $exc) {
            echo $exc->getTraceAsString();
        }
    }
    return $mdb2;
}
开发者ID:laiello,项目名称:coopcrucial,代码行数:28,代码来源:conexionBD.php

示例6: dbh

 public function dbh($dsn = null, $opt = null)
 {
     //init
     if (null != $dsn) {
         $this->dsn = $dsn;
     }
     if (null != $opt) {
         $this->opt = $opt;
     }
     //connect => $dsn = 'pgsql://someuser:apasswd@localhost/thedb';
     $this->dbh =& MDB2::factory($this->dsn, $this->opt);
     //sanity
     if (self::err($this->dbh, "dbh() : init-db")) {
         return null;
     }
     //re-init
     $this->dbh->setFetchMode(MDB2_FETCHMODE_ASSOC);
     //more options
     $this->dbh->setOption('result_buffering', true);
     $this->dbh->setOption('multi_query', true);
     //set here the utf-8
     $utf8[] = " SET NAMES 'utf8' COLLATE utf8_unicode_ci ";
     $utf8[] = " SET character_set_client='utf8'          ";
     $utf8[] = " SET character_set_connection='utf8'      ";
     for ($i = 0; $i < @count($utf8); $i++) {
         $bfsql = trim($utf8[$i]);
         self::query($bfsql, "ERROR: {$bfsql}");
     }
     //give it back ;-)
     return $this->dbh;
 }
开发者ID:bayugyug,项目名称:LDAP-Api,代码行数:31,代码来源:com.utils.mysqldbh.class.php

示例7: __construct

 private function __construct()
 {
     Plank_Logger::log('Singleton', get_class($this) . ' singleton created.', L_TRACE);
     $config = Plank_Config::getInstance();
     $config = $config->getArea('database');
     if (!$config || !isset($config['connections'])) {
         throw new Plank_Exception_Database_Config('Databases not configured');
     }
     $connections = explode(',', $config['connections']);
     foreach ($connections as $connection) {
         if (isset($config['dsn_' . $connection])) {
             $this->connections[$connection] = MDB2::factory($config['dsn_' . $connection]);
             if (PEAR::isError($this->connections[$connection])) {
                 throw new Plank_Exception_Database('DB Error! ' . $this->connections[$connection]->getMessage() . ' ' . $this->connections[$connection]->getUserInfo());
             }
             if (SHOWDEBUG) {
                 $this->connections[$connection]->setOption('debug', 1);
                 $this->connections[$connection]->setOption('log_line_break', "<br/>");
             }
             $this->connections[$connection]->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE);
             $this->connections[$connection]->setFetchMode(MDB2_FETCHMODE_ASSOC);
             if (PEAR::isError($this->connections[$connection])) {
                 throw new Plank_Exception_Database_Connection('Error connecting ' . $connection . ': ' . $this->connections[$connection]->getMessage() . ' ' . $this->connections[$connection]->getUserInfo());
             }
         } else {
             throw new Plank_Exception_Database_Config('No DSN for DB Connection ' . $connection);
         }
     }
 }
开发者ID:aquarion,项目名称:Plank,代码行数:29,代码来源:DB.php

示例8: array

/**
 * This function is a replacement for ADONewConnection, it does some
 * basic additional configuration and prepares the table prefix stuff
 *
 * @param $conf usually $conf['database'] in Flyspray
 * @return object
 */
function &NewDatabase($conf = array())
{
    if (!is_array($conf) || extract($conf, EXTR_REFS | EXTR_SKIP) < 5) {
        die('Flyspray was unable to connect to the database. ' . 'Check your settings in flyspray.conf.php');
    }
    $dbpass = rawurlencode($dbpass);
    if ($dbtype == 'sqlite') {
        $dsn = "{$dbtype}:///{$dbname}?mode=0666";
    } else {
        $dsn = "{$dbtype}://{$dbuser}:{$dbpass}@{$dbhost}/{$dbname}?charset=utf8";
    }
    $db =& MDB2::factory($dsn);
    $db->loadModule('Extended', 'x', false);
    if (defined('IN_UPGRADER') || defined('IN_SETUP')) {
        $db->loadModule('Manager');
    }
    $dbprefix = isset($dbprefix) ? $dbprefix : '';
    if ($db === false || !empty($dbprefix) && !preg_match('/^[a-z][a-z0-9_]+$/i', $dbprefix)) {
        die('Flyspray was unable to connect to the database. ' . 'Check your settings in flyspray.conf.php');
    }
    define('DB_PREFIX', $dbprefix);
    $db->setFetchMode(MDB2_FETCHMODE_ASSOC);
    $db->setOption('debug', true);
    $db->setOption('debug_handler', '_table_prefix');
    $db->setOption('quote_identifier', true);
    // upgrader can handle that on its own
    if (!defined('IN_UPGRADER') && !defined('IN_SETUP') || defined('DEBUG_SQL')) {
        $db->setErrorHandling(PEAR_ERROR_CALLBACK, 'show_dberror');
    }
    return $db;
}
开发者ID:negram,项目名称:flyspray,代码行数:38,代码来源:class.database.php

示例9: connectDbLazy

 /**
  * Connect to databases, but create instance not before the first time
  * a query gets executed.
  */
 private function connectDbLazy()
 {
     $this->connection = MDB2::factory($this->dsn);
     if (PEAR::isError($this->connection)) {
         die("Error while lazy connecting: " . $this->connection->getMessage() . "\ndsn was: " . print_r($this->dsn) . "\n");
     }
 }
开发者ID:rettichschnidi,项目名称:naturvielfalt,代码行数:11,代码来源:Db.php

示例10: myDB

 public function myDB($host, $user, $pwd, $db, $port)
 {
     $dsn = array('phptype' => 'pgsql', 'username' => $user, 'password' => $pwd, 'hostspec' => $host, 'database' => $db, 'port' => $port);
     if ($this->log) {
         $this->writeLog(print_r($dsn, true));
     }
     $options = array('result_buffering' => false);
     $this->db =& MDB2::factory($dsn, $options);
     //$this->db=& MDB2::connect($dsn,$options);
     if (!$this->db || PEAR::isError($this->db)) {
         if ($this->log) {
             $this->writeLog('Connect Error: ' . $dns);
         }
         $this->dbFehler('Connect ' . print_r($dsn, true), $this->db->getMessage());
         die($this->db->getMessage());
     }
     $this->db->setFetchMode(MDB2_FETCHMODE_ASSOC);
     if ($this->log) {
         $this->writeLog('Connect: ok ');
     }
     $sql = 'SELECT version()';
     $rs = $this->getOne($sql);
     if ($this->log) {
         $this->writeLog(print_r($rs, true));
     }
     preg_match('/PostgreSQL\\s*([\\d]+)\\.([\\d]+)\\..*/', $rs['version'], $ver);
     if ($ver[1] == '9' and $ver[2] >= '3' or $ver[1] >= '10') {
         $this->JVer = true;
     }
     if ($this->log) {
         $this->writeLog(print_r($ver, true) . "!" . $this->JVer . '!');
     }
     return $this->db;
 }
开发者ID:vanloswang,项目名称:kivitendo-crm,代码行数:34,代码来源:mdb.php

示例11: connect

 public function connect($dsn, $type = false, $options = false)
 {
     // Currently there are only two options: pear_mdb2 and php_native_mysql
     $connected = false;
     if ($type == 'php_native_mysql') {
         $this->db = mysql_connect($dsn->hostspec, $dsn->username, $dsn->password);
         if ($this->db) {
             if ($dsn->database) {
                 mysql_select_db($dsn->database, $this->db);
             }
             $this->dsn = $dsn;
             $connected = true;
         }
     } else {
         if ($type == 'pear_mdb2') {
             require_once 'MDB2.php';
             $this->db =& MDB2::factory($dsn, $options);
             if (PEAR::isError($this->db)) {
                 $this->errors[] = $this->db->getMessage();
             } else {
                 $connected = true;
                 $this->db->setFetchMode(MDB2_FETCHMODE_ASSOC);
             }
         }
     }
     if (!$connected) {
         $errors[] = 'Unable to connect to database using type: ' . $type;
         return false;
     } else {
         return $this->db;
     }
 }
开发者ID:ghbarratt,项目名称:sitesketch,代码行数:32,代码来源:DatabaseHandler.class.php

示例12: init

 /**
 	|
 	|  @init
 	|
 	|  @description
 	|      - init
 	|
 	|  @parameters
 	|      -
 	|
 	|
 	|  @return
 	|      -
 	|
 	**/
 public function init()
 {
     //create connection
     debug("init() : start init [ self::{$_Dsn} ]");
     //try
     self::$_Mdb =& MDB2::factory(self::$_Dsn, self::$_Opt);
     //sanity-chk
     if (self::err(self::$_Mdb, "init::FAILED")) {
         return null;
     }
     //misc options set here
     self::$_Mdb->setFetchMode(MDB2_FETCHMODE_ASSOC);
     //more options
     self::$_Mdb->setOption('result_buffering', true);
     self::$_Mdb->setOption('multi_query', true);
     //set here the utf-8
     $utf8[] = " SET NAMES 'utf8' COLLATE utf8_unicode_ci ";
     $utf8[] = " SET character_set_client='utf8'          ";
     $utf8[] = " SET character_set_connection='utf8'      ";
     for ($i = 0; $i < @count($utf8); $i++) {
         $bfsql = trim($utf8[$i]);
         self::query($bfsql, "ERROR: {$bfsql}");
         debug("init() : utf-8 [ {$bfsql} ]");
     }
     debug("init() : done  init [ self::{$_Mdb} ]");
     return self::$_Mdb;
 }
开发者ID:bayugyug,项目名称:LDAP-Api,代码行数:42,代码来源:com.utils.msqldb.class.php

示例13: __construct

 public function __construct()
 {
     $dsn = DB_TYPE . "://" . DB_USER . ":" . DB_PASS . "@" . DB_HOST . "/" . DB_DATABASE;
     $this->mdb2 =& MDB2::factory($dsn);
     if (PEAR::isError($this->mdb2)) {
         die($this->mdb2->getMessage());
     }
 }
开发者ID:par-orillonsoft,项目名称:my-website,代码行数:8,代码来源:SQL.class.php

示例14: __construct

 function __construct($dsn)
 {
     $this->dbh =& MDB2::factory($dsn);
     if (PEAR::isError($this->dbh)) {
         die($this->dbh->getMessage());
     }
     $this->dbh->setFetchMode(MDB2_FETCHMODE_ASSOC);
 }
开发者ID:nanasess,项目名称:xdo,代码行数:8,代码来源:MDB2.php

示例15: tearDown

 function tearDown()
 {
     $db = MDB2::factory(DB_DSN);
     $db->query('TRUNCATE langtkursus_tilmelding_ny');
     $db->query('TRUNCATE langtkursus_rate');
     $db->query('TRUNCATE langtkursus_tilmelding_rate');
     $db->query('TRUNCATE betaling');
 }
开发者ID:vih,项目名称:vih.dk,代码行数:8,代码来源:LangekursertilmeldingTest.php


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