/** * 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; }
/** * 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; } } } }
/** * 次のシーケンス値を取得する. * * @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); }
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); }
/** * 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"); } }
/** * 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; }
function db_connect($dbtype = 'mysql') { $dbhost = 'localhost'; $dbuser = '******'; $dbpass = '******'; 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; } } } }
function __construct() { $this->mdb = MDB2::connect($GLOBALS['BX_config']['dsn']); if (MDB2::isError($this->mdb)) { die('unable to connect to db'); } }
/** * 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; }
/** * 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; }
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; }
/** * 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; } } } }
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; }
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); }
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; }
function dbConnectDSN($dsn, $options = false) { // create database connection $db = MDB2::connect($dsn, $options); $db->loadModule('Extended'); // and fetch result as associative arrays $db->setFetchMode(MDB2_FETCHMODE_ASSOC); $db->query("SET NAMES utf8"); return $db; }
function &s_db_slink() { $dsn = array('phptype' => "mysql", 'username' => $_SERVER['SINASRV_DB4_USER_R'], 'password' => $_SERVER['SINASRV_DB4_PASS_R'], 'hostspec' => $_SERVER['SINASRV_DB4_HOST_R'], 'port' => $_SERVER['SINASRV_DB4_PORT_R'], 'database' => $_SERVER['SINASRV_DB4_NAME_R'], 'charset' => 'utf8'); $db = MDB2::connect($dsn); if (MDB2::isError($db)) { die(s_error($db->getMessage())); } $db->setFetchMode(MDB2_FETCHMODE_ASSOC); return $db; }
/** * @description 构造函数,创建一个连接 * */ public function __construct($host, $port, $user, $passwd, $dbName, $logFile = null) { $dsn = "mysql://{$user}:{$passwd}@{$host}:{$port}/{$dbName}?charset=utf8&new_link=true"; $options = array('debug' => 2, 'portability' => MDB2_PORTABILITY_ALL); $this->_mConnection =& MDB2::connect($dsn, $options); if (MDB2::isError($this->_mConnection)) { die(MDB2::errorMessage($this->_mConnection)); } $this->_logFile = str_replace('.date.', date('.Ymd.'), $logFile); $this->_logFile = str_replace('dbname', $dbName, $this->_logFile); }
public function __construct($dsn) { require_once 'MDB2.php'; $this->dsn = $dsn; $this->conn = MDB2::connect($this->dsn); if (PEAR::isError($this->conn)) { die("MDB2 Error - Cannot connect: " . $this->conn->getUserInfo() . "\n"); } $this->conn->setFetchMode(MDB2_FETCHMODE_ASSOC); $this->conn->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL); }
public function connect() { $dbhost = "localhost"; $dbname = "nlogview"; $dbuser = "******"; $dbpass = "******"; $sqlstr = "mysql://{$dbuser}:{$dbpass}@{$dbhost}/{$dbname}"; $this->db =& MDB2::connect($sqlstr); if (PEAR::isError($this->db)) { die("{$sqlstr} :: Can't connect: " . $this->db->getMessage()); } }
function db_connect() { $dsn = array('phptype' => 'mysql', 'username' => 'analytics', 'password' => '4T4r!an@lyt5', 'hostspec' => 'localhost'); $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)) { die($mdb2->getMessage()); } return $mdb2; }
public static function establishConnection($cmd) { $config = new config(); $dsn = $config->getDSN(); if ($cmd = 'open') { return MDB2::connect($dsn); } else { if ($cmd = 'close') { return null; } } }
/** * Funcion que muestra el listado de botones * @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 "; $pager_options = array('mode' => 'Sliding', 'perPage' => 16, 'delta' => 2, 'extraVars' => array('a' => $_REQUEST['a'])); $data = Pager_Wrapper_MDB2($odbconn, $sql, $pager_options); include getTemplate('boton.lista.php'); return; }
/** * Connects to the db * * @return object DB The database object * @access private */ function &_db_Connect(&$dsn) { $this->_debugMessage('_db_Connect($dsn)'); if (is_object($this->db)) { return $this->db; } if (is_object($dsn)) { return $dsn; } $db =& MDB2::connect($dsn); $this->_testFatalAbort($db, __FILE__, __LINE__); return $db; }
private function __construct() { $dsn = array('phptype' => 'mysql', 'username' => DB_USER, 'password' => DB_PASS, 'hostspec' => DB_IP, 'database' => DB_NAME); // Connect to Database $this->_handle =& MDB2::connect($dsn); if (PEAR::isError($this->_handle)) { die($this->_handle->getMessage()); } // Set Default Fetch Mode $this->_handle->setFetchMode(MDB2_FETCHMODE_ASSOC); // Keep Studly Caps Naming Convention $this->_handle->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE); }
/** * Funcion que muestra el listado de Perfiles * @return void */ function listar() { global $db; // Database connection $odbconn = MDB2::connect($db['dsn'], $db['opts']); $odbconn->setFetchMode(MDB2_FETCHMODE_ASSOC); $sql = "SELECT id,ARRAY_TO_STRING(ARRAY[nombre1, nombre2, apellido1,apellido2], ' ') as nombre \n FROM usuario\n WHERE activo = '1'\n AND tipo = '1'"; $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(); include getTemplate('medico.lista.php'); return; }
function mdb2() { static $mdb2; if (isset($mdb2)) { return $mdb2; } $mdb2 = MDB2::connect(config('DSN')); if (MDB2::isError($mdb2)) { fatal_error($mdb2->getMessage()); } $mdb2->exec('SET SESSION group_concat_max_len = 65536'); $mdb2->exec("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'"); return $mdb2; }
private function makeHandle($dsn) { //echo $dsn; $db =& MDB2::connect($dsn); // print_r($db); if (PEAR::isError($db)) { die($db->getMessage()); } $db->loadModule('Extended'); if (PEAR::isError($db)) { die($db->getMessage()); } else { return $db; } }
/** * Funcion que muestra el listado de Perfiles * @return void */ function listar() { global $db; // Database connection $odbconn = MDB2::connect($db['dsn'], $db['opts']); $odbconn->setFetchMode(MDB2_FETCHMODE_ASSOC); $sql = "SELECT * FROM horario \n WHERE estado = '1'\n Order by id"; $pager_options = array('mode' => 'Sliding', 'perPage' => 5, 'delta' => 2, 'extraVars' => array('a' => $_REQUEST['a'])); $data = Pager_Wrapper_MDB2($odbconn, $sql, $pager_options); // Mensaje a mostrar en el template $msj = flashData(); // templates include getTemplate('horario.lista.php'); return; }
function setUp() { $this->dsn = $GLOBALS['dsn']; $this->options = $GLOBALS['options']; $this->database = $GLOBALS['database']; $this->db =& MDB2::connect($this->dsn, $this->options); if (MDB2::isError($this->db)) { $this->assertTrue(false, 'Could not connect to database in setUp'); exit; } $this->db->setDatabase($this->database); $this->fields = array('user_name', 'user_password', 'subscribed', 'user_id', 'quota', 'weight', 'access_date', 'access_time', 'approved'); $this->types = array('text', 'text', 'boolean', 'integer', 'decimal', 'float', 'date', 'time', 'timestamp'); $this->clearTables(); }