* @link https://www.oos-shop.de * @subpackage adodb */ /** * Initializes the database connection. * * This function loads up ADODB and starts the database * connection using the required parameters then it sets * the table prefixes and xartables up and returns true * * @access protected * @global object db database connection object * @global integer ADODB_FETCH_MODE array fectching by associative or numeric keyed arrays * @global array oosDB_tables database tables used by MyOOS [Shopsystem] * @return bool true on success, false on failure */ function oosDBInit() { // Get database parameters $dbtype = OOS_DB_TYPE; $dbhost = OOS_DB_SERVER; $dbname = OOS_DB_DATABASE; // Decode encoded DB parameters if (OOS_ENCODED == '1') { $dbuname = base64_decode(OOS_DB_USERNAME); $dbpass = base64_decode(OOS_DB_PASSWORD); } else { $dbuname = OOS_DB_USERNAME; $dbpass = OOS_DB_PASSWORD; } // Start connection global $ADODB_CACHE_DIR; $ADODB_CACHE_DIR = oos_get_local_path(OOS_TEMP_PATH . 'adodb_cache/'); $dbconn = ADONewConnection($dbtype); if (!$dbconn->Connect($dbhost, $dbuname, $dbpass, $dbname)) { $dbpass = "****"; $dbuname = "****"; die("$dbtype://$dbuname:$dbpass@$dbhost/$dbname failed to connect " . $dbconn->ErrorMsg()); } global $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $GLOBALS['oosDB_connections'][0] = $dbconn; $GLOBALS['oosDB_tables'] = array(); return TRUE; } /** * Get a list of database connections * * @access public * @global array xarDB_connections array of database connection objects * @return array array of database connection objects */ function &oosDBGetConn() { // we only want to return the first connection here // perhaps we'll add linked list capabilities to this soon return $GLOBALS['oosDB_connections'][0]; } /** * Get an array of database tables * * @access public * @global array oosDB_tables array of database tables * @return array array of database tables */ function &oosDBGetTables() { return $GLOBALS['oosDB_tables']; } /** * Import module tables in the array of known tables * * @access protected * @global oostable array */ function oosDB_importTables($tables) { // assert('is_array($tables)'); $GLOBALS['oosDB_tables'] = array_merge($GLOBALS['oosDB_tables'], $tables); } function oos_db_input($sStr) { if (function_exists('mysqli::escape_string ')) { return mysqli::escape_string ($sStr); } return addslashes($sStr); } function oos_db_perform($table, $data, $action = 'INSERT', $parameters = '') { // Get database information $dbconn =& oosDBGetConn(); reset($data); if ($action == 'INSERT') { $query = 'INSERT INTO ' . $table . ' ('; foreach ( array_keys($data) as $columns ) { $query .= $columns . ', '; } $query = substr($query, 0, -2) . ') values ('; reset($data); foreach ($data as $value) { switch ((string)$value) { case 'now()': $query .= 'now(), '; break; case 'null': $query .= 'null, '; break; default: $query .= '\'' . oos_db_input($value) . '\', '; break; } } $query = substr($query, 0, -2) . ')'; } elseif ($action == 'UPDATE') { $query = 'UPDATE ' . $table . ' set '; foreach($data as $columns => $value) { switch ((string)$value) { case 'now()': $query .= $columns . ' = now(), '; break; case 'null': $query .= $columns .= ' = null, '; break; default: $query .= $columns . ' = \'' . oos_db_input($value) . '\', '; break; } } $query = substr($query, 0, -2) . ' where ' . $parameters; } return $dbconn->Execute($query); } function oos_db_prepare_input($sStr) { if (is_string($sStr)) { return trim(stripslashes($sStr)); } elseif (is_array($sStr)) { reset($sStr); foreach($sStr as $key => $value) { $sStr[$key] = oos_db_prepare_input($value); } return $sStr; } else { return $sStr; } } function oosDBOutput($sStr) { if (get_magic_quotes_gpc()) { return mysqli::escape_string (stripslashes($sStr)); } else { return mysqli::escape_string ($sStr); } } function dosql($table, $flds) { // Get database information $dbconn =& oosDBGetConn(); $dict = NewDataDictionary($dbconn); $taboptarray = array('mysql' => 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;', 'REPLACE'); $sqlarray = $dict->createTableSQL($table, $flds, $taboptarray); $dict->executeSqlArray($sqlarray); } function idxsql($idxname, $table, $idxflds) { // Get database information $dbconn =& oosDBGetConn(); $dict = NewDataDictionary($dbconn); $sqlarray = $dict->CreateIndexSQL($idxname, $table, $idxflds); $dict->executeSqlArray($sqlarray); }