function DBConnect() { global $db; $db = ADONewConnection('mysql'); $db->autoRollback = true; $db->PConnect(_DBHOST, _DBUSER, _DBPASS, _DBNAME) or die($db->ErrorMsg()); }
/** * get ado-connection * * @return ado-connection */ function getdb() { global $cfg; // build DSN switch ($cfg["db_type"]) { case "mysql": $dsn = 'mysql://' . $cfg["db_user"] . ':' . $cfg["db_pass"] . '@' . $cfg["db_host"] . '/' . $cfg["db_name"]; if ($cfg["db_pcon"]) { $dsn .= '?persist'; } break; case "sqlite": $dsn = 'sqlite://' . $cfg["db_host"]; if ($cfg["db_pcon"]) { $dsn .= '/?persist'; } break; case "postgres": $dsn = 'postgres://' . $cfg["db_user"] . ':' . $cfg["db_pass"] . '@' . $cfg["db_host"] . '/' . $cfg["db_name"]; if ($cfg["db_pcon"]) { $dsn .= '?persist'; } break; default: showErrorPage('No valid Database-Type specfied. <br>valid : mysql/sqlite/postgres<br>Check your database settings in the config.db.php file.'); } // connect $db = @ADONewConnection($dsn); // check connection if (!$db) { showErrorPage('Could not connect to database :<br><em>' . $dsn . '</em><br>Check your database settings in the config.db.php file.'); } // return db-connection return $db; }
function findSetDbDriver($persistent) { switch (DB_API) { case "adodb": error_reporting(E_ALL); /*show all the error messages*/ require_once 'adodb.inc.php'; require_once 'adodb-pear.inc.php'; global $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; if ($persistent == 0) { $this->storeDbConnection =& ADONewConnection(DB_TYPE); if (!$this->storeDbConnection->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME)) { print DBErrorCodes::code1(); print $this->storeDConnection->ErrorMsg(); } } else { $this->storeDbConnection =& ADONewConnection(DB_TYPE); if (!isset($this->storeDbConnection)) { if (!$this->storeDbConnection->PConnect(DB_HOST, DB_USER, DB_PASS, DB_NAME)) { print ErrorCodes::code1(); print $this->storeDbConnection->ErrorMsg(); } } } /*else*/ break; default: print "Can't find the appropriate DB Abstraction Layer \n <BR>"; break; } /*end switch*/ }
function sess_open($sess_path, $sess_name, $persist = null) { $database = $GLOBALS['ADODB_SESSION_DB']; $driver = $GLOBALS['ADODB_SESSION_DRIVER']; $host = $GLOBALS['ADODB_SESSION_CONNECT']; $password = $GLOBALS['ADODB_SESSION_PWD']; $user = $GLOBALS['ADODB_SESSION_USER']; $GLOBALS['ADODB_SESSION_TBL'] = !empty($GLOBALS['ADODB_SESSION_TBL']) ? $GLOBALS['ADODB_SESSION_TBL'] : 'sessions'; $db_object =& ADONewConnection($driver); if ($persist) { switch ($persist) { default: case 'P': $result = $db_object->PConnect($host, $user, $password, $database); break; case 'C': $result = $db_object->Connect($host, $user, $password, $database); break; case 'N': $result = $db_object->NConnect($host, $user, $password, $database); break; } } else { $result = $db_object->Connect($host, $user, $password, $database); } if ($result) { $GLOBALS['ADODB_SESS_CONN'] =& $db_object; } return $result; }
function connect() { if ($this->openqrm->get('config', 'DATABASE_TYPE') === "db2") { $db =& ADONewConnection('odbc'); $db->PConnect($this->openqrm->get('config', 'DATABASE_NAME'), $this->openqrm->get('config', 'DATABASE_USER'), $this->openqrm->get('config', 'DATABASE_PASSWORD')); $db->SetFetchMode(ADODB_FETCH_ASSOC); return $db; } else { if ($this->openqrm->get('config', 'DATABASE_TYPE') === "oracle") { $db = NewADOConnection("oci8po"); $db->Connect($this->openqrm->get('config', 'DATABASE_NAME'), $this->openqrm->get('config', 'DATABASE_USER'), $this->openqrm->get('config', 'DATABASE_PASSWORD')); } else { if (strlen($this->openqrm->get('config', 'DATABASE_PASSWORD'))) { $dsn = $this->openqrm->get('config', 'DATABASE_TYPE') . '://'; $dsn .= $this->openqrm->get('config', 'DATABASE_USER') . ':'; $dsn .= $this->openqrm->get('config', 'DATABASE_PASSWORD') . '@'; $dsn .= $this->openqrm->get('config', 'DATABASE_SERVER') . '/'; $dsn .= $this->openqrm->get('config', 'DATABASE_NAME') . '?persist'; } else { $dsn = $this->openqrm->get('config', 'DATABASE_TYPE') . '://'; $dsn .= $this->openqrm->get('config', 'DATABASE_USER') . '@'; $dsn .= $this->openqrm->get('config', 'DATABASE_SERVER') . '/'; $dsn .= $this->openqrm->get('config', 'DATABASE_NAME') . '?persist'; } $db =& ADONewConnection($dsn); } } $db->SetFetchMode(ADODB_FETCH_ASSOC); return $db; }
public function connect() { $conn =& ADONewConnection('mysql'); $conn->SetFetchMode(ADODB_FETCH_ASSOC); $conn->PConnect($GLOBALS['system']['host'], $GLOBALS['system']['user'], $GLOBALS['system']['pass'], $GLOBALS['system']['db']); return $conn; }
function getSettings($ontology_abbrv) { global $driver, $host, $username, $password, $database; $settings = array(); $strSql = "select * from ontology where ontology_abbrv='{$ontology_abbrv}'"; $db = ADONewConnection($driver); $db->Connect($host, $username, $password, $database); $row = $db->GetRow($strSql); if (!empty($row)) { $settings['ontology_name'] = $row['ontology_abbrv']; $settings['ontology_fullname'] = $row['ontology_fullname']; $settings['ns_main'] = $row['ontology_graph_url']; $settings['ns_main_original'] = $row['ontology_url']; $settings['remote_store_endpoint'] = $row['end_point']; } $settings['ns_rdf'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; $settings['ns_rdfs'] = 'http://www.w3.org/2000/01/rdf-schema#'; $settings['ns_owl'] = 'http://www.w3.org/2002/07/owl#'; $settings['base_oboInOwl'] = 'http://www.geneontology.org/formats/oboInOwl#'; $settings['core_terms'] = array(); $strSql = "select * from key_terms where ontology_abbrv='{$ontology_abbrv}' ORDER BY term_label"; $results = $db->GetAll($strSql); if ($results != false) { foreach ($results as $result) { if ($result['is_root'] == 1) { $settings['core_terms'][$result['term_url']] = $result['term_label'] . ' (root class)'; } else { $settings['core_terms'][$result['term_url']] = $result['term_label']; } } } return $settings; }
function &Connect($info = NULL) { if (!(strtolower(substr(PHP_OS, 0, 3)) === 'win')) { // Non Windows platform die("Microsoft Access or SQL Server is supported on Windows server only."); } $GLOBALS["ADODB_FETCH_MODE"] = ADODB_FETCH_BOTH; $GLOBALS["ADODB_COUNTRECS"] = FALSE; $conn = ADONewConnection('ado_mssql'); $conn->debug = $this->Debug; $conn->debug_echo = FALSE; if (!$info) { $info = "Provider=SQLNCLI11;Persist Security Info=False;Data Source=186.64.110.212;Initial Catalog=PbMillenium2;User Id=consultas;Password=consultas*;DataTypeCompatibility=80"; // ADO connection string } if ($this->Debug) { $conn->raiseErrorFn = $GLOBALS["EW_ERROR_FN"]; } if ($this->CodePage > 0) { $conn->charPage = $this->CodePage; } $conn->Connect($info, FALSE, FALSE); // Set date format $conn->Execute("SET DATEFORMAT ymd"); $conn->raiseErrorFn = ''; return $conn; }
function openConnection() { if ($this->connection == NULL) { require DIR_FS_CONFIG . "inc/config.php"; $this->session_name = SESSION_NAME; $connection = ADONewConnection($db_management_system); if ($connection->PConnect($db_host, $db_user, $db_password, $db_name)) { $connection->debug = $debug; $this->connection = $connection; return true; } else { $this->setErrorMsg("DataBase connection error."); return false; } } else { if (is_a($this->connection, '__PHP_Incomplete_Class')) { require DIR_FS_CONFIG . "inc/config.php"; $this->session_name = SESSION_NAME; $connection = ADONewConnection($db_management_system); if ($connection->PConnect($db_host, $db_user, $db_password, $db_name)) { $connection->debug = $debug; $this->connection = $connection; return true; } else { $this->setErrorMsg("DataBase connection error."); return false; } } else { return true; } } }
public static final function getConnector($ctx, $connString) { $db = null; // SQLite db init if (strpos($connString, "sqlite") === 0) { $db =& ADONewConnection('sqlite'); $db->debug = true; $connString = substr($connString, strlen("sqlite://"), strlen($connString)); $db->PConnect($connString); $connectorClass = "SQLiteConnector"; } else { if (strpos($connString, "mysql") === 0) { $db =& ADONewConnection($connectionString); $db->debug = true; $connectorClass = "MySQLConnector"; } } if (!is_null($db) && $db->IsConnected()) { self::$log->debug("Detected DB type: " . $db->databaseType); $dbc = new $connectorClass($ctx, $db); } else { self::$log->error("Could not connect to DB ({$connString})"); return false; } return $dbc; }
function db_connect_real($host, $user, $pass, $db_name, $db_type, $port = "3306", $db_ssl = false, $retries = 20) { global $cnn_id; $i = 0; $dsn = "{$db_type}://" . rawurlencode($user) . ":" . rawurlencode($pass) . "@" . rawurlencode($host) . "/" . rawurlencode($db_name) . "?persist"; if ($db_ssl && $db_type == "mysql") { $dsn .= "&clientflags=" . MYSQL_CLIENT_SSL; } elseif ($db_ssl && $db_type == "mysqli") { $dsn .= "&clientflags=" . MYSQLI_CLIENT_SSL; } if ($port != "3306") { $dsn .= "&port=" . $port; } while ($i <= $retries) { $cnn_id = ADONewConnection($dsn); if ($cnn_id) { $cnn_id->EXECUTE("set names 'utf8'"); return $cnn_id; } $i++; usleep(40000); } die("FATAL: Cannot connect to MySQL server on '{$host}'. Please make sure you have specified a valid MySQL database name in 'include/config.php'\n"); return 0; }
function connect_db($my_db_array, $db) { global $db, $dbport, $ADODB_SESSION_DRIVER, $ADODB_SESSION_CONNECT, $ADODB_SESSION_DB, $ADODB_SESSION_USER, $ADODB_SESSION_PWD; //connect to database via adodb $ADODB_SESSION_DRIVER = $my_db_array['driver']; $ADODB_SESSION_DB = $my_db_array['database']; $ADODB_SESSION_USER = $my_db_array['db_user']; $ADODB_SESSION_PWD = $my_db_array['db_pass']; $ADODB_SESSION_CONNECT = $my_db_array['db_host']; $dbport = $my_db_array['port']; $db_prefix = $my_db_array['prefix']; $ADODB_NEVER_PERSIST = true; $ADODB_COUNTRECS = false; // This *deeply* improves the speed of adodb. if (!function_exists('mysql_connect')) { die("The mysql_connect function is not loaded - you need the php-mysql module installed for this game to function"); return 0; } if (!empty($dbport)) { $ADODB_SESSION_CONNECT .= ":{$dbport}"; } $db = ADONewConnection("{$ADODB_SESSION_DRIVER}"); $db->debug = 0; $db->autoRollback = true; $result = $db->Connect("{$ADODB_SESSION_CONNECT}", "{$ADODB_SESSION_USER}", "{$ADODB_SESSION_PWD}", "{$ADODB_SESSION_DB}"); if (!$result) { die("Unable to connect to the database: " . $db->ErrorMsg()); return 0; } return $result; }
function _init_adodb_library(&$ci) { $db_var = false; $debug = false; $show_errors = true; $active_record = false; $db = NULL; if (!isset($dsn)) { // fallback to using the CI database file include APPPATH . 'config/database' . EXT; $group = 'default'; $dsn = $db[$group]['dbdriver'] . '://' . $db[$group]['username'] . ':' . $db[$group]['password'] . '@' . $db[$group]['hostname'] . '/' . $db[$group]['database']; } // Show Message Adodb Library PHP if ($show_errors) { require_once BASEPATH . 'packages/adodb5/adodb-errorhandler.inc' . EXT; } // $ci is by reference, refers back to global instance $ci->adodb =& ADONewConnection($dsn); // Use active record adodbx $ci->adodb->setFetchMode(ADODB_FETCH_ASSOC); if ($db_var) { // Also set the normal CI db variable $ci->db =& $ci->adodb; } if ($active_record) { require_once BASEPATH . 'packages/adodb5/adodb-active-record.inc' . EXT; ADOdb_Active_Record::SetDatabaseAdapter($ci->adodbx); } if ($debug) { $ci->adodb->debug = true; } }
private function __construct() { $db = ADONewConnection('mysql', 'pear:extend'); $db->createdatabase = true; $db->Connect("jinahadam.db.4081957.hostedresource.com", "jinahadam", "Relevation#666", "jinahadam"); $this->_handle =& $db; }
/** * Opens connection to the database. * You must call this function after instanciating your class, before doing queries. * Otherways all queries will fail! You also must have authentificated a user, before * you can use this class! */ function open($dbhost = "", $dbuser = "", $dbpasswd = "", $database = "") { global $c; // initialize configuratin variables. if ($dbhost == "") { $dbhost = $c["dbhost"]; } if ($dbuser == "") { $dbuser = $c["dbuser"]; } if ($dbpasswd == "") { $dbpasswd = $c["dbpasswd"]; } if ($database == "") { $database = $c["database"]; } if ($c["dbdriver"] == "mysql") { $this->ADODB = NewADOConnection($this->type); $this->ADODB->PConnect($dbhost, $dbuser, $dbpasswd, $database); } else { if ($c["dbdriver"] == "mssql") { $this->ADODB =& ADONewConnection("ado_mssql"); $dsn = "PROVIDER=MSDASQL;DRIVER={SQL Server};SERVER=" . $dbhost . ";DATABASE=" . $database . ";UID=" . $dbuser . ";PWD=" . $dbpasswd . ";"; $this->ADODB->Connect($dsn); } } }
/** * 数据库类 * @return string */ public static function get_db($config = 'default') { global $db; if ($db && $db->databaseName) { return $db; } $db_config = \config\Db::${$config}; $db_connect = new \config\Db(); include_once ROOT_PATH . 'lib/adodb/adodb.inc.php'; $db =& ADONewConnection($db_config["driver"]); $db->debug = 0; ini_set($db_config["driver"] . '.default_port', $db_config["port"]); $db->Connect($db_config["host"], $db_config["dbuser"], $db_config["dbpassword"], $db_config["dbname"]); $ADODB_CACHE_DIR = ROOT_PATH . "data/db"; $db->query('SET NAMES UTF8'); $db->SetFetchMode(2); //这只缓存时间 if (!defined('CacheTime')) { define('CacheTime', 600); } if (!$db) { die('不能连接数据库.\\n'); } //print_r($db); $GLOBALS['db'] = $db; return $db; }
/** * Retrieve a specific field from a LDAP filter. * * @param str $dsn * @param str $filter * @param str $field * @param bool $all : return all records if true * @return str or array if $all = true */ function get_field($dsn, $filter, $field, $all = false) { // Force autoloading if (!class_exists('ADOConnection')) { return null; } // Try to connect $ldaplink = ADONewConnection($dsn); $return = null; if (!$ldaplink) { // Wrong DSN return $return; } $ldaplink->SetFetchMode(ADODB_FETCH_ASSOC); $rs = $ldaplink->Execute($filter); if ($rs) { while ($arr = $rs->FetchRow()) { if (isset($arr[$field])) { // Retrieve field $return[] = $arr[$field]; if ($all === false) { break; } } } } // Disconnect $ldaplink->Close(); return $all ? $return : array_shift($return); }
function WikiDB_backend_ADODB($dbparams) { $parsed = parseDSN($dbparams['dsn']); $this->_dbparams = $dbparams; $this->_parsedDSN =& $parsed; $this->_dbh =& ADONewConnection($parsed['phptype']); if (DEBUG & _DEBUG_SQL) { $this->_dbh->debug = true; $GLOBALS['ADODB_OUTP'] = '_sql_debuglog'; } $this->_dsn = $parsed; // persistent is defined as DSN option, or with a config value. // phptype://username:password@hostspec/database?persistent=false if (!empty($parsed['persistent']) or DATABASE_PERSISTENT) { $conn = $this->_dbh->PConnect($parsed['hostspec'], $parsed['username'], $parsed['password'], $parsed['database']); } else { $conn = $this->_dbh->Connect($parsed['hostspec'], $parsed['username'], $parsed['password'], $parsed['database']); } // Since 1.3.10 we use the faster ADODB_FETCH_NUM, // with some ASSOC based recordsets. $GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_NUM; $this->_dbh->SetFetchMode(ADODB_FETCH_NUM); $GLOBALS['ADODB_COUNTRECS'] = false; $prefix = isset($dbparams['prefix']) ? $dbparams['prefix'] : ''; $this->_table_names = array('page_tbl' => $prefix . 'page', 'version_tbl' => $prefix . 'version', 'link_tbl' => $prefix . 'link', 'recent_tbl' => $prefix . 'recent', 'nonempty_tbl' => $prefix . 'nonempty'); $page_tbl = $this->_table_names['page_tbl']; $version_tbl = $this->_table_names['version_tbl']; $this->page_tbl_fields = "{$page_tbl}.id AS id, {$page_tbl}.pagename AS pagename, " . "{$page_tbl}.hits AS hits"; $this->links_field_list = array('id', 'pagename'); $this->page_tbl_field_list = array('id', 'pagename', 'hits'); $this->version_tbl_fields = "{$version_tbl}.version AS version, " . "{$version_tbl}.mtime AS mtime, " . "{$version_tbl}.minor_edit AS minor_edit, {$version_tbl}.content AS content, " . "{$version_tbl}.versiondata AS versiondata"; $this->version_tbl_field_list = array('version', 'mtime', 'minor_edit', 'content', 'versiondata'); $this->_expressions = array('maxmajor' => "MAX(CASE WHEN minor_edit=0 THEN version END)", 'maxminor' => "MAX(CASE WHEN minor_edit<>0 THEN version END)", 'maxversion' => "MAX(version)", 'notempty' => "<>''", 'iscontent' => "{$version_tbl}.content<>''"); $this->_lock_count = 0; }
public function createInstance() { require_once '/path/to/adodb_lite/adodb.inc.php'; $dsn = $this->settings['db.dsn']; $db = ADONewConnection($dsn); return $db; }
function testsql() { //define('ADODB_FORCE_NULLS',1); include '../adodb.inc.php'; include '../tohtml.inc.php'; //========================== // This code tests an insert $sql = "\r\r\nSELECT * \r\r\nFROM ADOXYZ WHERE id = -1"; // Select an empty record from the database $conn =& ADONewConnection("mysql"); // create a connection //$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $conn->debug = 1; $conn->PConnect("localhost", "root", "", "test"); // connect to MySQL, testdb $conn->Execute("delete from adoxyz where lastname like 'Smith%'"); $rs = $conn->Execute($sql); // Execute the query and get the empty recordset $record = array(); // Initialize an array to hold the record data to insert // Set the values for the fields in the record $record["firstname"] = 'null'; $record["lastname"] = "Smith\$@//"; $record["created"] = time(); //$record["id"] = -1; // Pass the empty recordset and the array containing the data to insert // into the GetInsertSQL function. The function will process the data and return // a fully formatted insert sql statement. $insertSQL = $conn->GetInsertSQL($rs, $record); $conn->Execute($insertSQL); // Insert the record into the database //========================== // This code tests an update $sql = "\r\r\nSELECT * \r\r\nFROM ADOXYZ WHERE lastname=" . $conn->qstr($record['lastname']); // Select a record to update $rs = $conn->Execute($sql); // Execute the query and get the existing record to update if (!$rs) { print "<p>No record found!</p>"; } $record = array(); // Initialize an array to hold the record data to update // Set the values for the fields in the record $record["firstName"] = "Caroline" . rand(); $record["lasTname"] = "Smithy Jones"; // Update Caroline's lastname from Miranda to Smith $record["creAted"] = '2002-12-' . (rand() % 30 + 1); $record['num'] = 3921; // Pass the single record recordset and the array containing the data to update // into the GetUpdateSQL function. The function will process the data and return // a fully formatted update sql statement. // If the data has not changed, no recordset is returned $updateSQL = $conn->GetUpdateSQL($rs, $record); $conn->Execute($updateSQL); // Update the record in the database print "<p>Rows Affected=" . $conn->Affected_Rows() . "</p>"; $rs = $conn->Execute("select * from adoxyz where lastname like 'Smith%'"); adodb_pr($rs); rs2html($rs); }
/** * A method to re-initialize connections to the CMSMS configured database. * This method should be used by any UDT's or other plugins that use any other method * than the standard CMSMS supplied database object to connect to a database. * */ function &adodb_connect() { $gCms = cmsms(); $config = $gCms->GetConfig(); $str = 'pear:date:extend'; if (isset($config['db_transactions'])) { $str .= ':transaction'; } $dbinstance = ADONewConnection($config['dbms'], $str); $dbinstance->raiseErrorFn = "adodb_error"; $conn_func = isset($config['persistent_db_conn']) && $config['persistent_db_conn'] == true ? 'PConnect' : 'Connect'; if (!empty($config['db_port'])) { $dbinstance->port = $config['db_port']; } $connect_result = $dbinstance->{$conn_func}($config['db_hostname'], $config['db_username'], $config['db_password'], $config['db_name']); if (FALSE == $connect_result) { $str = "Attempt to connect to database {$config['db_name']} on {$config['db_username']}@{$config['db_hostname']} failed"; trigger_error($str, E_USER_ERROR); die($str); } $dbinstance->raiseErrorFn = null; $dbinstance->SetFetchMode(ADODB_FETCH_ASSOC); if ($config['debug'] == true) { $dbinstance->debug = true; } if (!empty($config['default_encoding']) && $config['default_encoding'] == 'utf-8' && $config['set_names'] == true) { $dbinstance->Execute("SET NAMES 'utf8'"); } return $dbinstance; }
public function __construct(array $config = array()) { parent::__construct($config); if (isset($config['adodb_dir'])) { require_once $config['adodb_dir'] . DIRECTORY_SEPARATOR . 'adodb.inc.php'; } if ($config['adodb_error'] == 'exception') { require_once ADODB_DIR . DIRECTORY_SEPARATOR . 'adodb-exceptions.inc.php'; } if (!defined('_ADODB_LAYER')) { throw new AleExceptionCache('ADOdb layer not defined'); } if (isset($config['db']) && is_resource($config['db'])) { $this->db = $config['db']; } else { if (!isset($config['dsn'])) { throw new AleExceptionCache('ADOdb dsn (Data Source Name) config missing'); } $this->db = ADONewConnection($config['dsn']); if ($this->db == false) { throw new AleExceptionCache('ADODb connection failed'); } } $this->nameQuote = $this->db->nameQuote; }
function owpDBInit() { // Get database parameters $dbtype = OWP_DB_TYPE; $dbhost = OWP_DB_SERVER; $dbname = OWP_DB_DATABASE; // Decode encoded DB parameters if (OWP_ENCODED == '1') { $dbuname = base64_decode(OWP_DB_USERNAME); $dbpass = base64_decode(OWP_DB_PASSWORD); } else { $dbuname = OWP_DB_USERNAME; $dbpass = OWP_DB_PASSWORD; } // Database connection is a global (for now) global $db; // Start connection $ADODB_CACHE_DIR = OWP_DB_CACHE_PATH; $db = ADONewConnection($dbtype); $dbh = $db->Connect($dbhost, $dbuname, $dbpass, $dbname); if (!$dbh) { $dbpass = ""; die("{$dbtype}://{$dbuname}:{$dbpass}@{$dbhost}/{$dbname} failed to connect" . $db->ErrorMsg()); } global $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; // force oracle to a consistent date format for comparison methods later on if (strcmp($dbtype, 'oci8') == 0) { $db->Execute("alter session set NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"); } return true; }
/** * Create a singleton of ADODB or ADODBLite; This driver works for * both. Just specify the correct directory in * config->db->options->adodbDir. * The directory in which adodbDir resides in must be in your * include_path. * * @access public * @throws Framework_DB_Exception on failure * @return object Instance of ADODB[Lite] connected to the DB */ public function singleton() { if (!is_null(parent::$db) && parent::$db instanceof ADOConnection) { return parent::$db; } // Manually include files, ADODB does not follow naming conventions if (empty($this->options->adodbDir)) { throw new Framework_DB_Exception('Error: you must set $config->db->options->adodbDir'); } $path = (string) $this->options->adodbDir . DIRECTORY_SEPARATOR; if (!(include_once $path . 'adodb-exceptions.inc.php') || !(include_once $path . 'adodb.inc.php')) { throw new Framework_DB_Exception('Error: could not include ADODB files'); } // Connect try { parent::$db = ADONewConnection($this->dsn); } catch (Exception $error) { throw new Framework_DB_Exception($error->getMessage(), $error->getCode()); } // Fetch Modes $fetchModes = array('ADODB_FETCH_DEFAULT' => ADODB_FETCH_DEFAULT, 'ADODB_FETCH_NUM' => ADODB_FETCH_NUM, 'ADODB_FETCH_ASSOC' => ADODB_FETCH_ASSOC, 'ADODB_FETCH_BOTH' => ADODB_FETCH_BOTH); $fetchMode = ADODB_FETCH_ASSOC; if (isset($this->options->fetchMode) && isset($fetchModes[(string) $this->options->fetchMode])) { $fetchMode = $fetchModes[(string) $this->options->fetchMode]; } parent::$db->SetFetchMode($fetchMode); return parent::$db; }
function IPplanDbf() { // create a connection id $this->ds =& ADONewConnection(DBF_TYPE); $this->ds->debug = DBF_DEBUG; // some local locales only accept 24 hour date formats - MSSQL? if (DBF_TYPE == "mssql" or DBF_TYPE == "ado_mssql" or DBF_TYPE == "odbc_mssql") { $this->ds->fmtTimeStamp = "'Y-m-d H:i:s'"; } if (DBF_PERSISTENT) { // Fix issue with Reverse DNS imports that use nested database calls if (DBF_TYPE == "mysql" or DBF_TYPE == "maxsql" or DBF_TYPE == "postgres7") { $this->ds->autoRollback = FALSE; } if ($this->ds->PConnect(DBF_HOST, DBF_USER, DBF_PASSWORD, DBF_NAME)) { $this->ds->SetFetchMode(ADODB_FETCH_ASSOC); return $this->ds; } } else { if ($this->ds->Connect(DBF_HOST, DBF_USER, DBF_PASSWORD, DBF_NAME) != false) { $this->ds->SetFetchMode(ADODB_FETCH_ASSOC); return $this->ds; } } // kill connection info if error - probably bogus database name unset($this->ds); return false; }
private function __construct() { $connectionSettings = ConfigHandler::LoadConfigFile("db"); switch ($connectionSettings['type']) { case 'cassandra': require_once(ROOT_PDIR . 'core/libs/phpcassa-0.7.a.4/connection.php'); require_once(ROOT_PDIR . 'core/libs/core/ADODB_cassandra.class.php'); $this->connection = new ADODB_cassandra(); $this->connection->connect($connectionSettings['server'], null, null, $connectionSettings['name']); //var_dump($this->connection); die(); break; default: $dsn = "{$connectionSettings['type']}://" . "{$connectionSettings['user']}:{$connectionSettings['pass']}" . "@{$connectionSettings['server']}" . "/{$connectionSettings['name']}" . "?persist&fetchmode=ASSOC"; $this->connection =& ADONewConnection($dsn); break; } // No go? if (!$this->connection) return; // Caching? // @todo Make this a config option. //$this->connection->memCache = true; //$this->connection->memCacheHost = 'localhost'; //$this->connection->memCacheCompress = false; }
function &Connect($info = NULL) { $GLOBALS["ADODB_FETCH_MODE"] = ADODB_FETCH_BOTH; $GLOBALS["ADODB_COUNTRECS"] = FALSE; if (EW_USE_ADODB) { if (EW_USE_MYSQLI) { $conn = ADONewConnection('mysqli'); } else { $conn = ADONewConnection('mysqlt'); } } else { $conn = new mysqlt_driver_ADOConnection(); } $conn->debug = $this->Debug; $conn->debug_echo = FALSE; if (!$info) { $info = array("host" => $this->Host, "port" => $this->Port, "user" => $this->Username, "pass" => $this->Password, "db" => $this->DbName); } $conn->port = intval($info["port"]); if ($this->Debug) { $conn->raiseErrorFn = $GLOBALS["EW_ERROR_FN"]; } $conn->Connect($info["host"], $info["user"], $info["pass"], $info["db"]); if ($this->MySqlCharset != "") { $conn->Execute("SET NAMES '" . $this->MySqlCharset . "'"); } $conn->raiseErrorFn = ''; return $conn; }
public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions = null) { global $CFG; $driverstatus = $this->driver_installed(); if ($driverstatus !== true) { throw new dml_exception('dbdriverproblem', $driverstatus); } ob_start(); $this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions); $this->preconfigure_dbconnection(); require_once $CFG->libdir . '/adodb/adodb.inc.php'; $this->adodb = ADONewConnection($this->get_dbtype()); // See MDL-6760 for why this is necessary. In Moodle 1.8, once we start using NULLs properly, // we probably want to change this value to ''. $this->adodb->null2null = 'A long random string that will never, ever match something we want to insert into the database, I hope. \''; if (!empty($this->dboptions['dbpersist'])) { // Use persistent connection $connected = $this->adodb->PConnect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); } else { // Use single connection $connected = $this->adodb->Connect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); } $dberr = ob_get_contents(); ob_end_clean(); if (!$connected) { throw new dml_connection_exception($dberr); } $this->configure_dbconnection(); return true; }
function get_conn() { global $db_host, $db_conn, $db_user, $db_pass, $db_name; if ($db_conn != null && $db_conn->IsConnected()) { return $db_conn; } // error_log("new conection"); // db_conn = ADONewConnection('mysqli'); //$status = $db_conn->PConnect('localhost', $db_user, $db_pass, $db_name); $db_conn = ADONewConnection('postgres9'); $status = $db_conn->PConnect($db_host, $db_user, $db_pass, $db_name); if ($status === true) { if ($db_conn->IsConnected() !== true) { error_log("db can't connect"); //return false; exit("no db connection"); } //$db_conn->SetFetchMode(ADODB_FETCH_ASSOC); $ADODB_FETCH_MODE = 'ADODB_FETCH_ASSOC'; $db_conn->debug = false; return $db_conn; } else { error_log("db can't connect"); exit("no db connection"); } }
public static function init($params) { self::$dbConnParams = $params; self::$dbConn =& ADONewConnection(self::$dbConnParams['type']); self::$dbConn->Connect(self::$dbConnParams['host'], self::$dbConnParams['user'], self::$dbConnParams['password'], self::$dbConnParams['name']); return true; }