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


PHP MDB2::connect方法代码示例

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


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

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

示例2: LiveUser_Admin_Perm_Container_MDB2_Simple

 /**
  * Constructor
  *
  * @access protected
  * @param  array  full liveuser configuration array
  * @return void
  * @see    LiveUser::factory()
  */
 function LiveUser_Admin_Perm_Container_MDB2_Simple(&$connectOptions)
 {
     if (is_array($connectOptions)) {
         $function = 'connect';
         if (isset($connectOptions['function'])) {
             $function = $connectOptions['function'];
             unset($connectOptions['function']);
         }
         foreach ($connectOptions as $key => $value) {
             if (isset($this->{$key})) {
                 $this->{$key} = $value;
             }
         }
         if (isset($connectOptions['connection']) && MDB2::isConnection($connectOptions['connection'])) {
             $this->dbc =& $connectOptions['connection'];
             $this->init_ok = true;
         } elseif (isset($connectOptions['dsn'])) {
             $this->dsn = $connectOptions['dsn'];
             $options = null;
             if (isset($connectOptions['options'])) {
                 $options = $connectOptions['options'];
             }
             $options['portability'] = MDB2_PORTABILITY_ALL;
             if ($function == 'singleton') {
                 $this->dbc =& MDB2::singleton($connectOptions['dsn'], $options);
             } else {
                 $this->dbc =& MDB2::connect($connectOptions['dsn'], $options);
             }
             if (!MDB2::isError($this->dbc)) {
                 $this->init_ok = true;
             }
         }
     }
 }
开发者ID:BackupTheBerlios,项目名称:hem,代码行数:42,代码来源:MDB2_Simple.php

示例3: nextVal

 /**
  * 次のシーケンス値を取得する.
  *
  * @param string $seq_name 取得するシーケンス名
  * @param integer 次のシーケンス値
  */
 function nextVal($seq_name)
 {
     $dsn = array('phptype' => DB_TYPE, 'username' => DB_USER, 'password' => DB_PASSWORD, 'protocol' => 'tcp', 'hostspec' => DB_SERVER, 'port' => DB_PORT, 'database' => DB_NAME);
     // SQL Azure では必ず新しいセッションを使用する
     $_conn = MDB2::connect($dsn, $options);
     return $_conn->nextID($seq_name, false);
 }
开发者ID:ryoogata,项目名称:eccube-SQLAzureSupport-plugin,代码行数:13,代码来源:SC_Query_Ex.php

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

示例5: login

/**
 * Check the login and password
 * @return void
 */
function login()
{
    global $db;
    $usuario = sanitize($_POST['usuario']);
    $clave = sanitize($_POST['clave']);
    $sql = "SELECT id,usuario,nombre1,apellido1,id_rol,tipo\n                FROM usuario \n                WHERE usuario = '{$usuario}'\n                AND   clave   = MD5('{$clave}')";
    $odbconn = MDB2::connect($db['dsn'], $db['opts']);
    $odbconn->setFetchMode(MDB2_FETCHMODE_ASSOC);
    $rst = $odbconn->queryRow($sql);
    $odbconn->disconnect();
    if (PEAR::isError($rst)) {
        return false;
    }
    if ($rst) {
        session_start();
        $_SESSION['user']['startTime'] = date("Y-m-d H:i");
        $_SESSION['user']['id_usuario'] = $rst['id'];
        $_SESSION['user']['usuario'] = $rst['usuario'];
        $_SESSION['user']['nombres'] = $rst['nombre1'];
        $_SESSION['user']['apellidos'] = $rst['apellido1'];
        $_SESSION['user']['rol'] = $rst['id_rol'];
        $_SESSION['user']['tipo'] = $rst['tipo'];
        $Modulo = new Modulo();
        $_SESSION['perms'] = $Modulo->getModulosPermitidos($rst['id_rol']);
        header('Location: ../../index.php');
    } else {
        header("Location: ../../login.php?login=false");
    }
}
开发者ID:agldiego,项目名称:sitio,代码行数:33,代码来源:autenticacion.php

示例6: dsn_connect

 /**
  * Connect to specific database
  *
  * @param  string  DSN for DB connections
  * @return object  PEAR database handle
  * @access private
  */
 function dsn_connect($dsn)
 {
     // Use persistent connections if available
     $db_options = array('persistent' => $this->db_pconn, 'emulate_prepared' => $this->debug_mode, 'debug' => $this->debug_mode, 'debug_handler' => 'mdb2_debug_handler', 'portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL);
     if ($this->db_provider == 'pgsql') {
         $db_options['disable_smart_seqname'] = true;
         $db_options['seqname_format'] = '%s';
     }
     $dbh = MDB2::connect($dsn, $db_options);
     if (MDB2::isError($dbh)) {
         $this->db_error = TRUE;
         $this->db_error_msg = $dbh->getMessage();
         raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 'message' => $dbh->getUserInfo()), TRUE, FALSE);
     } else {
         if ($this->db_provider == 'sqlite') {
             $dsn_array = MDB2::parseDSN($dsn);
             if (!filesize($dsn_array['database']) && !empty($this->sqlite_initials)) {
                 $this->_sqlite_create_database($dbh, $this->sqlite_initials);
             }
         } else {
             if ($this->db_provider != 'mssql' && $this->db_provider != 'sqlsrv') {
                 $dbh->setCharset('utf8');
             }
         }
     }
     return $dbh;
 }
开发者ID:DavidGarciaCat,项目名称:eyeos,代码行数:34,代码来源:rcube_mdb2.php

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

示例8: __construct

 function __construct()
 {
     $this->mdb = MDB2::connect($GLOBALS['BX_config']['dsn']);
     if (MDB2::isError($this->mdb)) {
         die('unable to connect to db');
     }
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:7,代码来源:aggregator.php

示例9: listar

 /**
  * Funcion que muestra el listado de medicamentos
  * @return void
  */
 function listar()
 {
     global $db;
     // Database connection
     $odbconn = MDB2::connect($db['dsn'], $db['opts']);
     $odbconn->setFetchMode(MDB2_FETCHMODE_ASSOC);
     $sql = "SELECT *\n                    FROM {$this->tabla}\n                    WHERE 1=1 ";
     if (isset($_REQUEST['buscar'])) {
         if ($_REQUEST['palabra']) {
             $sql .= " AND( upper(generico) LIKE '%" . strtoupper($_REQUEST['palabra']) . "%' \n                             OR codigo LIKE '%{$_REQUEST['palabra']}%'\n                            )";
             $show = true;
         }
         if ($_REQUEST['forma']) {
             $sql .= " AND codformfarm = '{$_REQUEST['forma']}' ";
             $show = true;
         }
     }
     $pager_options = array('mode' => 'Sliding', 'perPage' => 16, 'delta' => 2, 'extraVars' => array('a' => $_REQUEST['a']));
     $data = Pager_Wrapper_MDB2($odbconn, $sql, $pager_options);
     // Variables usadas en el template
     $ltipo = $this->listaTipoForma();
     $tipo = arregloLista($ltipo);
     $idforma = isset($_REQUEST['forma']) ? $_REQUEST['forma'] : '';
     include getTemplate('medicamento.lista.php');
     return;
 }
开发者ID:agldiego,项目名称:salud,代码行数:30,代码来源:Medicamento.class.php

示例10: listar

 /**
  * Funcion que muestra el listado de manuales
  * @return void
  */
 function listar()
 {
     global $db;
     $show = false;
     $display = "style=\"display:none;\"";
     // Database connection
     $odbconn = MDB2::connect($db['dsn'], $db['opts']);
     $odbconn->setFetchMode(MDB2_FETCHMODE_ASSOC);
     $sql = "SELECT *\n                    FROM {$this->tabla}\n                    WHERE 1=1 ";
     if (isset($_REQUEST['buscar'])) {
         if ($_REQUEST['palabra']) {
             $sql .= " AND( upper(nombre) LIKE '%" . strtoupper($_REQUEST['palabra']) . "%' \n                             OR codigo LIKE '%{$_REQUEST['palabra']}%'\n                             OR cups LIKE '%{$_REQUEST['palabra']}%') ";
             $show = true;
         }
         if ($_REQUEST['manual']) {
             $sql .= " AND manual = '{$_REQUEST['manual']}' ";
             $show = true;
         }
     }
     if ($show === true) {
         $display = "style=\"display:inline;\"";
     }
     $pager_options = array('mode' => 'Sliding', 'perPage' => 16, 'delta' => 2, 'extraVars' => array('a' => $_REQUEST['a']));
     $data = Pager_Wrapper_MDB2($odbconn, $sql, $pager_options);
     // Variable para el template
     $Manual = new Manual();
     $smanual = $Manual->lista();
     $manual = arregloLista($smanual);
     $idmanual = isset($_REQUEST['manual']) ? $_REQUEST['manual'] : '';
     // Mensaje a mostrar en el template
     $msj = flashData();
     include getTemplate('tarifa.lista.php');
     return;
 }
开发者ID:agldiego,项目名称:salud,代码行数:38,代码来源:Tarifa.class.php

示例11: dbConnect

function dbConnect()
{
    global $db_type;
    global $db_user;
    global $db_pass;
    global $db_host;
    global $db_name;
    global $sql_regexp;
    if (!(isset($db_user) && $db_user != "")) {
        include_once "header.inc.php";
        error(ERR_DB_NO_DB_USER);
        include_once "footer.inc.php";
        exit;
    }
    if (!(isset($db_pass) && $db_pass != "")) {
        include_once "header.inc.php";
        error(ERR_DB_NO_DB_PASS);
        include_once "footer.inc.php";
        exit;
    }
    if (!(isset($db_host) && $db_host != "")) {
        include_once "header.inc.php";
        error(ERR_DB_NO_DB_HOST);
        include_once "footer.inc.php";
        exit;
    }
    if (!(isset($db_name) && $db_name != "")) {
        include_once "header.inc.php";
        error(ERR_DB_NO_DB_NAME);
        include_once "footer.inc.php";
        exit;
    }
    if (!isset($db_type) || !($db_type == "mysql" || $db_type == "pgsql")) {
        include_once "header.inc.php";
        error(ERR_DB_NO_DB_TYPE);
        include_once "footer.inc.php";
        exit;
    }
    $dsn = "{$db_type}://{$db_user}:{$db_pass}@{$db_host}/{$db_name}";
    $db = MDB2::connect($dsn);
    $db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL);
    if (MDB2::isError($db)) {
        // Error handling should be put.
        error(MYSQL_ERROR_FATAL, $db->getMessage());
    }
    // Do an ASSOC fetch. Gives us the ability to use ["id"] fields.
    $db->setFetchMode(MDB2_FETCHMODE_ASSOC);
    /* erase info */
    $mysql_pass = $dsn = '';
    // Add support for regular expressions in both MySQL and PostgreSQL
    if ($db_type == "mysql") {
        $sql_regexp = "REGEXP";
    } elseif ($db_type == "pgsql") {
        $sql_regexp = "~";
    } else {
        error(ERR_DB_NO_DB_TYPE);
    }
    return $db;
}
开发者ID:kitpz2,项目名称:grupappz,代码行数:59,代码来源:database.inc.php

示例12: perform

 /**
  * Check if version number has changed and perfom additional upgarde code
  * Furthermore assign array with module menu names for the top right
  * module html seletor
  *
  * @param array $data
  */
 function perform($data)
 {
     // get os related separator to set include path
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         $tmp_separator = ';';
     } else {
         $tmp_separator = ':';
     }
     // set include path to the PEAR packages
     ini_set('include_path', SF_BASE_DIR . 'modules/common/PEAR' . $tmp_separator . ini_get('include_path'));
     unset($tmp_separator);
     // include PEAR DB class
     include_once SF_BASE_DIR . 'modules/common/PEAR/MDB2.php';
     // init system config array
     $this->B->sys = array();
     // include system config array $this->B->sys
     if (file_exists(SF_BASE_DIR . 'modules/common/config/config.php')) {
         include_once SF_BASE_DIR . 'modules/common/config/config.php';
     }
     // if setup was done
     if ($this->B->sys['info']['status'] == TRUE) {
         $this->B->dsn = array('phptype' => $this->B->sys['db']['type'], 'username' => $this->B->sys['db']['user'], 'password' => $this->B->sys['db']['passwd'], 'hostspec' => $this->B->sys['db']['host'], 'database' => $this->B->sys['db']['name']);
         $this->B->db =& MDB2::connect($this->B->dsn);
         if (MDB2::isError($this->B->db)) {
             trigger_error('Cannot connect to the database: ' . __FILE__ . ' ' . __LINE__, E_USER_ERROR);
         }
     } else {
         // switch to the admin section if we comes from the public section
         if (SF_SECTION == 'public') {
             @header('Location: ' . SF_BASE_LOCATION . '/index.php?admin=1');
             exit;
         }
         // launch setup screen
         include $this->B->M(MOD_COMMON, 'get_module_view', array('m' => 'setup', 'view' => 'index'));
         // Send the output buffer to the client
         ob_end_flush();
         exit;
     }
     // Check for upgrade
     if (MOD_COMMON_VERSION != (string) $this->B->sys['module']['common']['version']) {
         // set the new version num of this module
         $this->B->sys['module']['common']['version'] = MOD_COMMON_VERSION;
         $this->B->system_update_flag = TRUE;
         // include here additional upgrade code
     }
     if (SF_SECTION == 'admin') {
         // sort handler array by name
         ksort($this->B->handler_list);
         // assign template handler names array
         // this array is used to build the modul select form of the admin menu
         $this->B->tpl_mod_list = array();
         foreach ($this->B->handler_list as $key => $value) {
             if ($value['menu_visibility'] == TRUE) {
                 $this->B->tpl_mod_list[$key] = $value;
             }
         }
     }
 }
开发者ID:BackupTheBerlios,项目名称:smart-svn,代码行数:65,代码来源:class.common_sys_init.php

示例13: DB

 function DB()
 {
     $dsn = base_application_registry::getDSN();
     $this->ensure($dsn, "No DSN");
     if (!$this->db) {
         $this->db = MDB2::connect($dsn);
     }
     $this->ensure(!MDB2::isError($this->db), "Unable to connect to DB");
     return $this->db;
 }
开发者ID:jonolsson,项目名称:Saturday,代码行数:10,代码来源:Mapper-recovered.php

示例14: exec

 public function exec()
 {
     $db = MDB2::connect($this->_dsn);
     list($sql, $binds) = $this->to_sql();
     // echo $sql . "\n";
     $st = $db->prepare($sql);
     $rs = $st->execute($binds);
     $rows = $rs->fetchAll();
     return LR($rows);
 }
开发者ID:naoya,项目名称:PQ,代码行数:10,代码来源:pq.php

示例15: connect2db

function connect2db($DBMS, $dbhost, $dbuser, $dbpwd, $dbname)
{
    $dsn = "{$DBMS}://{$dbuser}:{$dbpwd}@{$dbhost}/{$dbname}";
    $db = MDB2::connect($dsn);
    if (MDB2::isError($db)) {
        die($db->getMessage('MySQL 無法連結資料庫'));
    }
    $db->exec('SET NAMES UTF8');
    return $db;
}
开发者ID:oopDaniel,项目名称:Website_BadGuy,代码行数:10,代码来源:db_func.php


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