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


PHP MDB2类代码示例

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


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

示例1: datatype_test_callback

/**
 * A test callback function to be used in the test class below for
 * ensuring that custom datatype callback features are handled
 * correctly.
 *
 * @param MDB2   $db         The MDB2 database reource object.
 * @param string $method     The name of the MDB2_Driver_Datatype_Common method
 *                           the callback function was called from. One of
 *                           "getValidTypes", "convertResult", "getDeclaration",
 *                           "compareDefinition", "quote" and "mapPrepareDatatype".
 *                           See {@link MDB2_Driver_Datatype_Common} for the
 *                           details of what each method does.
 * @param array $aParameters An array of parameters, being the parameters that
 *                           were passed to the method calling the callback
 *                           function.
 * @return mixed Returns the appropriate value depending on the method that
 *               called the function. See {@link MDB2_Driver_Datatype_Common}
 *               for details of the expected return values of the five possible
 *               calling methods.
 */
function datatype_test_callback(&$db, $method, $aParameters)
{
    // Ensure the datatype module is loaded
    if (is_null($db->datatype)) {
        $db->loadModule('Datatype', null, true);
    }
    // Lowercase method names for PHP4/PHP5 compatibility
    $method = strtolower($method);
    switch ($method) {
        // For all cases, return a string that identifies that the
        // callback method was able to call to the appropriate point
        case 'getvalidtypes':
            return 'datatype_test_callback::getvalidtypes';
        case 'convertresult':
            return 'datatype_test_callback::convertresult';
        case 'getdeclaration':
            return 'datatype_test_callback::getdeclaration';
        case 'comparedefinition':
            return 'datatype_test_callback::comparedefinition';
        case 'quote':
            return 'datatype_test_callback::quote';
        case 'mappreparedatatype':
            return 'datatype_test_callback::mappreparedatatype';
    }
}
开发者ID:ballistiq,项目名称:revive-adserver,代码行数:45,代码来源:MDB2_datatype_testcase.php

示例2: listar

 /**
  * Funcion que muestra el listado de medicamentos
  * @return void
  */
 function listar()
 {
     global $db;
     $titulo = '';
     if ($_REQUEST['tipo'] == '1') {
         $titulo = 'MEDICAMENTOS';
     } elseif ($_REQUEST['tipo'] == '2') {
         $titulo = 'LABORATORIO';
     } elseif ($_REQUEST['tipo'] == '3') {
         $titulo = 'IMAGENOLOGIA';
     } elseif ($_REQUEST['tipo'] == '4') {
         $titulo = 'PROCEDIMIENTO';
     }
     // Database connection
     $odbconn = MDB2::connect($db['dsn'], $db['opts']);
     $odbconn->setFetchMode(MDB2_FETCHMODE_ASSOC);
     $sql = "SELECT *\n                    FROM {$this->tabla}\n                    WHERE tipo = '{$_REQUEST['tipo']}'\n                    ";
     if (isset($_REQUEST['buscar'])) {
         if ($_REQUEST['palabra']) {
             $sql .= " AND( upper(nombre) LIKE '%" . strtoupper($_REQUEST['palabra']) . "%')";
             $show = true;
         }
     }
     $sql .= " ORDER BY id ASC";
     $pager_options = array('mode' => 'Sliding', 'perPage' => 16, 'delta' => 2, 'extraVars' => array('a' => $_REQUEST['a']));
     $data = Pager_Wrapper_MDB2($odbconn, $sql, $pager_options);
     // Mensaje a mostrar en el template
     $msj = flashData();
     // Variables usadas en el template
     include getTemplate('sugerencia.lista.php');
     return;
 }
开发者ID:agldiego,项目名称:salud,代码行数:36,代码来源:Sugerencia.class.php

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

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

示例5: perform

 /**
  * add message data
  *
  * @param array $data
  */
 function perform(&$data)
 {
     $mid = $this->B->db->nextId($this->B->sys['db']['table_prefix'] . 'earchive_messages');
     if (MDB2::isError($mid)) {
         trigger_error($result->getMessage() . "\n\nINFO: " . $result->userinfo . "\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR);
         return FALSE;
     }
     $sql = '
         INSERT INTO 
             ' . $this->B->sys['db']['table_prefix'] . 'earchive_messages
             (mid,lid,sender,subject,mdate,body,folder)
         VALUES
             (' . $mid . ',
              ' . $data['lid'] . ',
              "' . $data['sender'] . '",
              "' . $data['subject'] . '",
              "' . $data['mdate'] . '",
              "' . $data['body'] . '",
              "' . $data['folder'] . '")';
     $result = $this->B->db->query($sql);
     if (MDB2::isError($result)) {
         trigger_error($result->getMessage() . "\n\nINFO: " . $result->userinfo . "\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR);
         return FALSE;
     }
     return $mid;
 }
开发者ID:BackupTheBerlios,项目名称:smart-svn,代码行数:31,代码来源:class.earchive_add_message.php

示例6: db_connect

function db_connect($dbtype = 'mysql')
{
    $dbhost = 'localhost';
    $dbuser = 'analytics';
    $dbpass = '4T4r!an@lyt5';
    if ($dbtype == 'pear') {
        $dsn = array('phptype' => 'mysql', 'username' => $dbuser, 'password' => $dbpass, 'hostspec' => $dbhost);
        $options = array('debug' => 2, 'portability' => MDB2_PORTABILITY_ALL);
        // uses MDB2::factory() to create the instance
        // and also attempts to connect to the host
        $mdb2 = MDB2::connect($dsn, $options);
        if (PEAR::isError($mdb2)) {
            error($mdb2->getMessage());
        }
        return $mdb2;
    } else {
        if ($dbtype == 'mysql') {
            $mysql_conn = mysqli_connect($dbhost, $dbuser, $dbpass);
            if (mysqli_connect_errno()) {
                error("MySQL : Connect failed: %s\n" . mysqli_connect_error());
            }
            return $mysql_conn;
        } else {
            if ($dbtype == 'postgres') {
                $postgres_conn = pg_connect("host={$dbhost} user={$dbuser} password={$dbpass}");
                if (!$postgres_conn) {
                    error("PostGres : Connect failed: %s");
                }
                return $postgres_conn;
            }
        }
    }
}
开发者ID:rjevansatari,项目名称:Analytics,代码行数:33,代码来源:db.php

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

示例8: sanitizeDb

 static function sanitizeDb($db)
 {
     if (is_string($db)) {
         require_once 'MDB2.php';
         // $dsn = MDB2::parseDSN($db);
         $db = MDB2::connect($db);
     } else {
         if (is_object($db) && is_subclass_of($db, 'MDB2_Driver_Common')) {
             /* MDB2 driver */
         } else {
             if (is_array($db) && count(array_diff(array(0, 1, 2, 3, 4), array_keys($db))) == 0) {
                 $dsnString = $db[0] . '://' . $db[2] . ':' . $db[3] . '@' . $db[1] . '/' . $db[4];
                 $db = MDB2::connect($dsnString);
             } else {
                 if (is_array($db) && array_key_exists('phptype', $db)) {
                     $db = MDB2::connect($db);
                 } else {
                     throw new Exception('Invalid database');
                 }
             }
         }
     }
     $dsn = MDB2::parseDSN($db->dsn);
     if (!$dsn['database']) {
         // sometimes the database name is not set here, so try to recover
         $dsn['database'] = $db->database_name;
     }
     return array($db, $dsn);
 }
开发者ID:r3-gis,项目名称:EcoGIS,代码行数:29,代码来源:r3mdb2.php

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

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

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

示例12: R3AppInitDB

function R3AppInitDB()
{
    global $mdb2;
    global $dsn;
    require_once 'MDB2.php';
    if (!isset($dsn) || $dsn == '') {
        throw new Exception('Missing $dsn');
    }
    $txtDsn = $dsn['dbtype'] . '://' . $dsn['dbuser'] . ':' . $dsn['dbpass'] . '@' . $dsn['dbhost'] . '/' . $dsn['dbname'];
    $db = ezcDbFactory::create($txtDsn);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    PEAR::setErrorHandling(PEAR_ERROR_EXCEPTION);
    $mdb2 = MDB2::singleton($txtDsn);
    // Needed by user manager and import/export
    ezcDbInstance::set($db);
    if (isset($dsn['charset'])) {
        $db->exec("SET client_encoding TO '{$dsn['charset']}'");
        $mdb2->exec("SET client_encoding TO '{$dsn['charset']}'");
    }
    if (isset($dsn['search_path'])) {
        $db->exec("SET search_path TO {$dsn['search_path']}, public");
        $mdb2->exec("SET search_path TO {$dsn['search_path']}, public");
    }
    $db->exec("SET datestyle TO ISO");
    $mdb2->exec("SET datestyle TO ISO");
}
开发者ID:r3-gis,项目名称:EcoGIS,代码行数:26,代码来源:eco_app.php

示例13: perform

 /**
  * add user
  *
  * @param array $data
  * @return int user id or false on error
  */
 function perform($data)
 {
     $this->B->{$data}['error'] = FALSE;
     $error =& $this->B->{$data}['error'];
     if ($this->login_exists($data['user_data']['login']) > 0) {
         $error = 'Login exists';
         return FALSE;
     }
     $uid = $this->B->db->nextId($this->B->sys['db']['table_prefix'] . 'user_users');
     if (MDB2::isError($uid)) {
         trigger_error($uid->getMessage() . "\n" . $uid->userinfo . "\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR);
         $error = 'Unexpected error';
         return FALSE;
     }
     $sql = '
         INSERT INTO 
             ' . $this->B->sys['db']['table_prefix'] . 'user_users
             (uid,forename,lastname,email,login,passwd,status,rights)
         VALUES
             (' . $uid . ',
              "' . $data['user_data']['forename'] . '",
              "' . $data['user_data']['lastname'] . '",
              "' . $data['user_data']['email'] . '",
              "' . $data['user_data']['login'] . '",
              "' . $data['user_data']['passwd'] . '",
              ' . $data['user_data']['status'] . ',
              ' . $data['user_data']['rights'] . ')';
     $res = $this->B->db->query($sql);
     if (MDB2::isError($res)) {
         trigger_error($res->getMessage() . "\n" . $res->userinfo . "\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR);
         $error = 'Unexpected error';
         return FALSE;
     }
     return $uid;
 }
开发者ID:BackupTheBerlios,项目名称:smart-svn,代码行数:41,代码来源:class.user_add.php

示例14: perform

 /**
  * add list data in db table
  *
  * @param array $data
  */
 function perform(&$data)
 {
     // get list messages attachment folder string
     $list_folder = commonUtil::unique_md5_str();
     if (!@mkdir(SF_BASE_DIR . '/data/earchive/' . $list_folder, SF_DIR_MODE)) {
         trigger_error("Cannot create list messages attachment folder! Contact the administrator.\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR);
         return FALSE;
     }
     $lid = $this->B->db->nextId($this->B->sys['db']['table_prefix'] . 'earchive_lists');
     if (MDB2::isError($lid)) {
         trigger_error($result->getMessage() . "\n\nINFO: " . $result->userinfo . "\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR);
         return FALSE;
     }
     $sql = '
         INSERT INTO 
             ' . $this->B->sys['db']['table_prefix'] . 'earchive_lists
             (lid,name,email,emailserver,description,folder,status)
         VALUES
             (' . $lid . ',
              "' . $data['name'] . '",
              "' . $data['email'] . '",
              "' . $data['emailserver'] . '",
              "' . $data['description'] . '",
              "' . $list_folder . '",
              ' . $data['status'] . ')';
     $result = $this->B->db->query($sql);
     if (MDB2::isError($result)) {
         trigger_error($result->getMessage() . "\n\nINFO: " . $result->userinfo . "\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR);
         return FALSE;
     }
     return TRUE;
 }
开发者ID:BackupTheBerlios,项目名称:smart-svn,代码行数:37,代码来源:class.earchive_add_list.php

示例15: perform

 /**
  * Assign array with message attachments data
  *
  * @param array $data
  */
 function perform(&$data)
 {
     if (empty($data['mid']) || empty($data['var'])) {
         trigger_error("'mid' or 'var' is empty!\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR);
         return FALSE;
     }
     // get var name to store the result
     $this->B->{$data}['var'] = array();
     $_result =& $this->B->{$data}['var'];
     $comma = '';
     foreach ($data['fields'] as $f) {
         $_fields .= $comma . $f;
         $comma = ',';
     }
     $sql = "\n            SELECT\n                {$_fields}\n            FROM\n                {$this->B->sys['db']['table_prefix']}earchive_attach\n            WHERE\n                mid={$data['mid']}            \n            ORDER BY\n                file ASC";
     $result = $this->B->db->query($sql);
     if (MDB2::isError($result)) {
         trigger_error($result->getMessage() . "\n\nINFO: " . $result->userinfo . "\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR);
     }
     $_result = array();
     if (is_object($result)) {
         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
             $tmp = array();
             foreach ($data['fields'] as $f) {
                 $tmp[$f] = stripslashes($row[$f]);
             }
             $_result[] = $tmp;
         }
     }
     return TRUE;
 }
开发者ID:BackupTheBerlios,项目名称:smart-svn,代码行数:36,代码来源:class.earchive_get_attachments.php


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