function gs_db_connect(&$conn, $tag = '', $host, $user, $pwd, $db = null, $_backtrace_level = 0) { $caller_info = ''; if (GS_LOG_LEVEL >= GS_LOG_DEBUG) { $bt = debug_backtrace(); if (is_array($bt) && array_key_exists($_backtrace_level, $bt)) { $caller_info = ' for ' . @$bt[$_backtrace_level]['file'] . ':' . @$bt[$_backtrace_level]['line'] . ''; unset($bt); } } if (gs_db_is_connected($conn)) { //gs_log( GS_LOG_DEBUG, 'Using existing'. ($tag != '' ? ' "'.$tag.'"':'') .' DB connection'. ($conn->getCustomAttr('w') ? '':' (read-only)') . $caller_info ); // don't flood the log return 2; # using the existing connection } gs_log(GS_LOG_DEBUG, 'New' . ($tag != '' ? ' ' . str_pad($tag, 6) . '' : '') . ' DB connection' . $caller_info); if (!($conn = YADB_newConnection('mysql'))) { $conn = null; return false; } if (!$conn->connect($host, $user, $pwd, $db, array('reuse' => false, 'timeout' => 8))) { $lastNativeError = @$conn->getLastNativeError(); $lastNativeErrorMsg = @$conn->getLastNativeErrorMsg(); gs_log(GS_LOG_WARNING, 'Could not connect to' . ($tag != '' ? ' "' . $tag . '"' : '') . ' database!' . ($lastNativeError ? ' (#' . $lastNativeError . ' - ' . $lastNativeErrorMsg . ')' : '')); $conn = null; return false; } @$conn->setCharSet('utf8', 'utf8_unicode_ci'); @$conn->setQueryErrCb('gs_db_query_err_handler'); return 1; # opened a new connection }
function &factory($dbType) { return YADB_newConnection($dbType); }