function genericSqlQuery($sql, $args = false) { if ($args) { $result = $this->_backend->_dbh->query($sql, $args); } else { $result = $this->_backend->_dbh->query($sql); } if (DB::isError($result)) { $msg = $result->getMessage(); trigger_error("SQL Error: " . DB::errorMessage($result), E_USER_WARNING); return false; } else { return $result; } }
} $md5pw = md5($password); $showemail = @(bool) $showemail; $needsvn = @(bool) $needsvn; // hack to temporarily embed the "purpose" in // the user's "userinfo" column $userinfo = serialize(array($purpose, $moreinfo)); $created_at = gmdate('Y-m-d H:i'); $sth = $dbh->prepare("INSERT INTO users \n (handle, name, email, password, registered, showemail, homepage, userinfo, from_site, active, created)\n VALUES(?, ?, ?, ?, 0, ?, ?, ?, 'pecl', 0, ?)"); $res = $dbh->execute($sth, array($handle, $name, $email, $md5pw, $showemail, $homepage, $userinfo, $created_at)); if (DB::isError($res)) { //constraint violation, only email and handle(username) is unique if ($res->getCode() == -3) { display_error("Username or Email already taken"); } else { display_error("{$handle}: " . DB::errorMessage($res)); } $jumpto = "handle"; break; } /* Now do the SVN stuff */ if ($needsvn) { $error = posttohost('http://master.php.net/entry/svn-account.php', array("username" => $handle, "name" => $name, "email" => $email, "passwd" => $password, "note" => $purpose, "group" => 'pecl', "yesno" => 'yes')); if ($error) { display_error("Problem submitting the php.net account request: {$error}"); break; } } $display_form = false; $msg = "Requested from: {$_SERVER['REMOTE_ADDR']}\n" . "Username: {$handle}\n" . "Real Name: {$name}\n" . "Email: {$email}" . (@$showemail ? " (show address)" : " (hide address)") . "\n" . "Need php.net Account: " . (@$needsvn ? "yes" : "no") . "\n" . "Purpose:\n" . "{$purpose}\n\n" . "To handle: http://" . PEAR_CHANNELNAME . "/admin/?acreq={$handle}\n"; if ($moreinfo) {
/** * Modify address * @param string $alias modified alias * @param array $userdata new data * @return bool */ function modify($alias, $userdata) { if (!$this->writeable) { return $this->set_error(_("Address book is read-only")); } if (!$this->open()) { return false; } /* See if user exist */ $ret = $this->lookup($alias); if (empty($ret)) { return $this->set_error(sprintf(_("User \"%s\" does not exist"), $alias)); } /* make sure that new nickname is not used */ if (strtolower($alias) != strtolower($userdata['nickname'])) { /* same check as in add() */ $ret = $this->lookup($userdata['nickname']); if (!empty($ret)) { $error = sprintf(_("User '%s' already exist."), $ret['nickname']); return $this->set_error($error); } } /* Create query */ $query = sprintf("UPDATE %s SET nickname='%s', firstname='%s', " . "lastname='%s', email='%s', label='%s' " . "WHERE owner='%s' AND nickname='%s'", $this->table, $this->dbh->quoteString($userdata['nickname']), $this->dbh->quoteString($userdata['firstname']), $this->dbh->quoteString(!empty($userdata['lastname']) ? $userdata['lastname'] : ''), $this->dbh->quoteString($userdata['email']), $this->dbh->quoteString(!empty($userdata['label']) ? $userdata['label'] : ''), $this->owner, $this->dbh->quoteString($alias)); /* Do the insert */ $r = $this->dbh->simpleQuery($query); /* Check for errors */ if (DB::isError($r)) { return $this->set_error(sprintf(_("Database error: %s"), DB::errorMessage($r))); } return true; }
function DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE, $debuginfo = null) { if (is_int($code)) { $this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code, $mode, $level, $debuginfo); } else { $this->PEAR_Error("DB Error: {$code}", DB_ERROR, $mode, $level, $debuginfo); } }
/** * DB_Error constructor * * @param mixed $code DB error code, or string with error message * @param int $mode what "error mode" to operate in * @param int $level what error level to use for $mode & * PEAR_ERROR_TRIGGER * @param mixed $debuginfo additional debug info, such as the last query * * @see PEAR_Error */ function __construct($code = DB_ERROR, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE, $debuginfo = null) { if (is_int($code)) { parent::__construct('DB Error: ' . DB::errorMessage($code), $code, $mode, $level, $debuginfo); } else { parent::__construct("DB Error: {$code}", DB_ERROR, $mode, $level, $debuginfo); } }
private static function verificarCredenciais($sql) { $sucesso = false; self::$novoLogin = false; if (isset($_POST["user_login"])) { self::$login = (string) $_POST["user_login"]; } else { if (isset($_SESSION["user_login"])) { self::$login = (string) $_SESSION["user_login"]; } else { self::$login = ""; } } if (isset($_POST["senha_login"])) { self::$senha = (string) $_POST["senha_login"]; } else { if (isset($_SESSION["senha_login"])) { self::$senha = (string) $_SESSION["senha_login"]; } else { self::$senha = ""; } } if (self::$login and self::$senha) { self::$conexao = self::obterConexao(); if (self::$conexao) { $parametros = array("login" => self::$login, "senha" => md5(self::$senha)); $model_usuario_sistema = new ModelUsuario_Sistema($parametros); $usuario = DAO::query($sql, $model_usuario_sistema); if ($usuario) { $usuario = $usuario[0]; $sucesso = true; if (!isset($_SESSION["user_login"]) && !isset($_SESSION["senha_login"]) && $usuario->get('data_ultimo_acesso')) { $usuarioDAO = new Usuario_SistemaDAO(); $usuarioDAO->atualizarDataUltimoAcesso($usuario); } $_SESSION["user_login"] = $usuario->get("login"); $_SESSION["user_nome"] = $usuario->get("nome"); $_SESSION["senha_login"] = self::$senha; $_SESSION["id"] = $usuario->get("id"); $_SESSION["id_centro_custo"] = $usuario->get("id_centro_custo"); $_SESSION["centro_custo"] = $usuario->get("centro_custo"); $_SESSION["id_tipo_centro_custo"] = $usuario->get("tipo_centro_custo"); $_SESSION["id_centro_custo_superior"] = $usuario->get("id_superior"); $_SESSION["centro_custo_superior"] = $usuario->get("centro_superior"); $_SESSION["id_tipo_centro_custo_superior"] = $usuario->get("tipo_centro_custo_superior"); $_SESSION["id_cargo"] = $usuario->get("id_cargo"); $_SESSION["cargo"] = $usuario->get("cargo"); $_SESSION["data_ultimo_acesso"] = $usuario->get("data_ultimo_acesso"); $_SESSION["cpf"] = $usuario->get("cpf"); self::$novoLogin = ((string) isset($_REQUEST["user_login"]) || (string) isset($_REQUEST["url"])) && (string) isset($_REQUEST["senha_login"]) ? "1" : "0"; } else { $_SESSION["erro_login"] = "******"; } } else { $_SESSION["erro_login"] = DB::errorMessage(self::$conexao); } } return $sucesso; }
$aDsn = explode(':', $dsn); $dbtype = array_shift($aDsn); if (isset($db_functions[$dbtype]) && function_exists($db_functions[$dbtype])) { echo "{$IND}{$dbtype} database support present.<br />\n"; } elseif (!(bool) ini_get('enable_dl') || (bool) ini_get('safe_mode')) { do_err($dbtype . ' database support not present!'); } else { // Non-fatal error do_err($dbtype . ' database support not present or not configured! Trying to dynamically load ' . $dbtype . ' extension. Please note that it is advisable to not rely on dynamic loading of extensions.', FALSE); } // now, test this interface: $dbh = DB::connect($dsn, true); if (DB::isError($dbh)) { do_err('Database error: ' . htmlspecialchars(DB::errorMessage($dbh)) . ' in ' . $type . ' DSN.'); } $dbh->disconnect(); echo "{$IND}{$type} database connect successful.<br />\n"; } } else { $db_error = 'Required PHP PEAR DB support is not available.' . ' Is PEAR installed and is the include path set correctly to find <tt>DB.php</tt>?' . ' The include path is now: "<tt>' . ini_get('include_path') . '</tt>".'; do_err($db_error); } } else { echo $IND . "not using database functionality.<br />\n"; } ?> <p>Congratulations, your SquirrelMail setup looks fine to me!</p>
} else { $strOrderBy = $_GET["Order"]; $strPageLinkORD = $strPageLink; $strPageLink .= "&Order=" . $strOrderBy; } $sql .= "clients.Client_ID > 1 ORDER BY " . $strOrderBy; echo '<!--' . $sql . '-->'; if (DB::isError($res = $con->query($sql))) { die(DB::errorMessage($res)); } $limit = 16; $maxpages = 10; $pager = new DB_Pager($res, $from, $limit); $data = $pager->build(); if (DB::isError($data)) { die(DB::errorMessage($data)); } if (!$data) { // no results // pages table cells $render_pages = ' <tr> <td class="podTextCenter" colspan="2"><b>Found 0 Properties</b></td> </tr> '; // no results message $render = 'No results'; } else { // direct links to page numbers: foreach ($data['pages'] as $page => $start_row) { if ($page != $data['current']) {
public function connect($force = FALSE) { $flag = new Charcoal_ErrorReportingSwitcher(0, E_DEPRECATED); // 接続済みなら何もしない if ($this->_connected && !$force) { return; } $timer_handle = Charcoal_Benchmark::start(); $backend = $this->_backend; $user = $this->_user; $password = $this->_password; $db_name = $this->_db_name; $server = $this->_server; $charset = $this->_charset; require_once 'DB.php'; $DSN = array('phptype' => $backend->getValue(), 'username' => $user->getValue(), 'password' => $password->getValue(), 'hostspec' => $server->getValue(), 'database' => $db_name->getValue()); $DSN = v($DSN); $db_string = nl2br($DSN->toString()); try { log_info("debug,sql,data_source", "data_source", "connecting database: DSN=[{$db_string}]"); $db = DB::connect($DSN->toArray()); if (DB::isError($db)) { $msg = 'message=[' . DB::errorMessage($db) . "] DSN=[{$db_string}]"; log_error("debug,sql,data_source,error", "data_source", $msg); _throw(new Charcoal_DBException($msg)); } log_info("debug,sql,data_source", "data_source", "connected database: DSN=[{$db_string}]"); $this->_connection = $db; $this->_connected = true; // 文字化け対策 $charset = $this->_charset; if (!$charset->isEmpty()) { $charset = $charset->getValue(); switch (strtolower($charset)) { case 'utf8': $this->_query(s('SET NAMES `utf8`')); break; case 'ujis': $this->_query(s('SET NAMES `ujis`')); break; case 'sjis': $this->_query(s('SET NAMES `sjis`')); break; default: _throw(new DataSourceConfigException(s('charset'), s('INVALID_CHARSET_VALUE: ' . $charset))); } // $this->_query( "set character set $charset" ); } // 自動コミット $autocommit = $this->_autocommit; $this->_connection->autoCommit($autocommit->isTrue()); log_info("debug,sql,data_source", "data_source", "autocommit: [{$autocommit}]"); } catch (Exception $e) { _catch($e); $msg = __METHOD__ . " failed: [db_string]{$db_string}"; _throw(new Charcoal_DBDataSourceException($msg)); } // ログ $elapse = Charcoal_Benchmark::stop($timer_handle); log_debug("debug,sql,data_source", "data_source", "connect() end. time=[{$elapse}]sec."); }
function get($query, $from = 0, $class = "") { $res = $this->db->query($query); $pager = new DB_Pager($res, $from, $this->limit); $data = $pager->build(); if (DB::isError($data)) { return $this->raiseError(DB::errorMessage($data)); } if (!$data) { //return $this->raiseError("There were no results"); return $this->str_emptyresult; } if ($this->heading) { $this->table_Header($class); } $this->table_Body($pager, $from, $class); $this->table_Footer($class); if ($class) { $row1Style = array("class" => $class); if ($this->alternate_background) { $row2Style = array("class" => $class . $this->alternate_background_style); $this->table->altRowAttributes(1, $row1Style, $row2Style); } } return $this->meta_head($data) . "<br>" . $this->get_nav($data) . $this->table->toHTML() . $this->get_nav($data); }
/** * @param string $entity * type of entities to deal with * @param string $action * create, get, delete or some special action name. * @param array $params * array to be passed to function * @param null $extra * * @return array|int */ function civicrm_api($entity, $action, $params, $extra = NULL) { $apiRequest = array(); $apiRequest['entity'] = CRM_Utils_String::munge($entity); $apiRequest['action'] = CRM_Utils_String::munge($action); $apiRequest['version'] = civicrm_get_api_version($params); $apiRequest['params'] = $params; $apiRequest['extra'] = $extra; $apiWrappers = array(CRM_Utils_API_HTMLInputCoder::singleton(), CRM_Utils_API_NullOutputCoder::singleton(), CRM_Utils_API_ReloadOption::singleton(), CRM_Utils_API_MatchOption::singleton()); CRM_Utils_Hook::apiWrappers($apiWrappers, $apiRequest); try { require_once 'api/v3/utils.php'; require_once 'api/Exception.php'; if (!is_array($params)) { throw new API_Exception('Input variable `params` is not an array', 2000); } _civicrm_api3_initialize(); $errorScope = CRM_Core_TemporaryErrorScope::useException(); // look up function, file, is_generic $apiRequest += _civicrm_api_resolve($apiRequest); if (strtolower($action) == 'create' || strtolower($action) == 'delete' || strtolower($action) == 'submit') { $apiRequest['is_transactional'] = 1; $transaction = new CRM_Core_Transaction(); } // support multi-lingual requests if ($language = CRM_Utils_Array::value('option.language', $params)) { _civicrm_api_set_locale($language); } _civicrm_api3_api_check_permission($apiRequest['entity'], $apiRequest['action'], $apiRequest['params']); $fields = _civicrm_api3_api_getfields($apiRequest); // we do this before we _civicrm_api3_swap_out_aliases($apiRequest, $fields); if (strtolower($action) != 'getfields') { if (empty($apiRequest['params']['id'])) { $apiRequest['params'] = array_merge(_civicrm_api3_getdefaults($apiRequest, $fields), $apiRequest['params']); } //if 'id' is set then only 'version' will be checked but should still be checked for consistency civicrm_api3_verify_mandatory($apiRequest['params'], NULL, _civicrm_api3_getrequired($apiRequest, $fields)); } // For input filtering, process $apiWrappers in forward order foreach ($apiWrappers as $apiWrapper) { $apiRequest = $apiWrapper->fromApiInput($apiRequest); } $function = $apiRequest['function']; if ($apiRequest['function'] && $apiRequest['is_generic']) { // Unlike normal API implementations, generic implementations require explicit // knowledge of the entity and action (as well as $params). Bundle up these bits // into a convenient data structure. $result = $function($apiRequest); } elseif ($apiRequest['function'] && !$apiRequest['is_generic']) { _civicrm_api3_validate_fields($apiRequest['entity'], $apiRequest['action'], $apiRequest['params'], $fields); $result = isset($extra) ? $function($apiRequest['params'], $extra) : $function($apiRequest['params']); } else { return civicrm_api3_create_error("API (" . $apiRequest['entity'] . ", " . $apiRequest['action'] . ") does not exist (join the API team and implement it!)"); } // For output filtering, process $apiWrappers in reverse order foreach (array_reverse($apiWrappers) as $apiWrapper) { $result = $apiWrapper->toApiOutput($apiRequest, $result); } if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) { if ($result['is_error'] === 0) { return 1; } else { return 0; } } if (!empty($apiRequest['params']['format.only_id']) && isset($result['id'])) { return $result['id']; } if (CRM_Utils_Array::value('is_error', $result, 0) == 0) { _civicrm_api_call_nested_api($apiRequest['params'], $result, $apiRequest['action'], $apiRequest['entity'], $apiRequest['version']); } if (function_exists('xdebug_time_index') && CRM_Utils_Array::value('debug', $apiRequest['params']) && is_array($result)) { $result['xdebug']['peakMemory'] = xdebug_peak_memory_usage(); $result['xdebug']['memory'] = xdebug_memory_usage(); $result['xdebug']['timeIndex'] = xdebug_time_index(); } return $result; } catch (PEAR_Exception $e) { if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) { return 0; } $error = $e->getCause(); if ($error instanceof DB_Error) { $data["error_code"] = DB::errorMessage($error->getCode()); $data["sql"] = $error->getDebugInfo(); } if (!empty($apiRequest['params']['debug'])) { if (method_exists($e, 'getUserInfo')) { $data['debug_info'] = $error->getUserInfo(); } if (method_exists($e, 'getExtraData')) { $data['debug_info'] = $data + $error->getExtraData(); } $data['trace'] = $e->getTraceAsString(); } else { $data['tip'] = "add debug=1 to your API call to have more info about the error"; } $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest); if (!empty($apiRequest['is_transactional'])) { $transaction->rollback(); } return $err; } catch (API_Exception $e) { if (!isset($apiRequest)) { $apiRequest = array(); } if (CRM_Utils_Array::value('format.is_success', CRM_Utils_Array::value('params', $apiRequest)) == 1) { return 0; } $data = $e->getExtraParams(); $data['entity'] = CRM_Utils_Array::value('entity', $apiRequest); $data['action'] = CRM_Utils_Array::value('action', $apiRequest); $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest, $e->getCode()); if (CRM_Utils_Array::value('debug', CRM_Utils_Array::value('params', $apiRequest)) && empty($data['trace'])) { $err['trace'] = $e->getTraceAsString(); } if (!empty($apiRequest['is_transactional'])) { $transaction->rollback(); } return $err; } catch (Exception $e) { if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) { return 0; } $data = array(); $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest, $e->getCode()); if (!empty($apiRequest['params']['debug'])) { $err['trace'] = $e->getTraceAsString(); } if (!empty($apiRequest['is_transactional'])) { $transaction->rollback(); } return $err; } }
/** * Put new mail in queue and save in database. * * Mail_Queue_Container::put() * * @param string $time_to_send When mail have to be send * @param integer $id_user Sender id * @param string $ip Sender ip * @param string $from Sender e-mail * @param string $to Reciepient e-mail * @param string $hdrs Mail headers (in RFC) * @param string $body Mail body (in RFC) * @param bool $delete_after_send Delete or not mail from db after send * * @return mixed ID of the record where this mail has been put * or Mail_Queue_Error on error * @access public **/ function put($time_to_send, $id_user, $ip, $sender, $recipient, $headers, $body, $delete_after_send = true) { if (!is_object($this->db) || !is_a($this->db, 'DB_Common')) { $msg = 'DB::connect failed'; if (PEAR::isError($this->db)) { $msg .= ': ' . DB::errorMessage($this->db); } return new Mail_Queue_Error(MAILQUEUE_ERROR_CANNOT_CONNECT, $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__, $msg); } $id = $this->db->nextId($this->sequence); if (empty($id) || PEAR::isError($id)) { return new Mail_Queue_Error(MAILQUEUE_ERROR, $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__, 'Cannot create id in: ' . $this->sequence); } $query = sprintf("INSERT INTO %s (id, create_time, time_to_send, id_user, ip,\n sender, recipient, headers, body, delete_after_send)\n VALUES(%d, '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', %d)", $this->mail_table, $id, addslashes(date('Y-m-d H:i:s')), addslashes($time_to_send), addslashes($id_user), addslashes($ip), addslashes($sender), addslashes($recipient), addslashes($headers), addslashes($body), $delete_after_send); $res = $this->db->query($query); if (PEAR::isError($res)) { return new Mail_Queue_Error(MAILQUEUE_ERROR_QUERY_FAILED, $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__, 'DB::query failed - "' . $query . '" - ' . $res->toString()); } return $id; }
$aDsn = explode(':', $dsn); $dbtype = array_shift($aDsn); if (isset($db_functions[$dbtype]) && function_exists($db_functions[$dbtype])) { echo "{$IND}{$dbtype} database support present.<br />\n"; } elseif (!(bool) ini_get('enable_dl') || (bool) ini_get('safe_mode')) { do_err($dbtype . ' database support not present!'); } else { // Non-fatal error do_err($dbtype . ' database support not present or not configured! Trying to dynamically load ' . $dbtype . ' extension. Please note that it is advisable to not rely on dynamic loading of extensions.', FALSE); } // now, test this interface: $dbh = DB::connect($dsn, true); if (DB::isError($dbh)) { do_err('Database error: ' . sm_encode_html_special_chars(DB::errorMessage($dbh)) . ' in ' . $type . ' DSN.'); } $dbh->disconnect(); echo "{$IND}{$type} database connect successful.<br />\n"; } } else { $db_error = 'Required PHP PEAR DB support is not available.' . ' Is PEAR installed and is the include path set correctly to find <tt>DB.php</tt>?' . ' The include path is now: "<tt>' . ini_get('include_path') . '</tt>".'; do_err($db_error); } } else { echo $IND . "not using database functionality.<br />\n"; } // LDAP DB tests echo "Checking LDAP functions...<br />\n"; if (empty($ldap_server)) { echo $IND . "not using LDAP functionality.<br />\n";
function failQuery($res = NULL) { if ($res == NULL) { printf(_("Preference database error (%s). Exiting abnormally"), $this->error); } else { printf(_("Preference database error (%s). Exiting abnormally"), DB::errorMessage($res)); } exit; }
function modify($alias, $userdata) { if (!$this->writeable) { return $this->set_error(_("Addressbook is read-only")); } if (!$this->open()) { return false; } /* See if user exist */ $ret = $this->lookup($alias); if (empty($ret)) { return $this->set_error(sprintf(_("User '%s' does not exist"), $alias)); } /* Create query */ $query = sprintf("UPDATE %s SET nickname='%s', firstname='%s', " . "lastname='%s', email='%s', label='%s' " . "WHERE owner='%s' AND nickname='%s'", $this->table, $this->dbh->quoteString($userdata['nickname']), $this->dbh->quoteString($userdata['firstname']), $this->dbh->quoteString($userdata['lastname']), $this->dbh->quoteString($userdata['email']), $this->dbh->quoteString($userdata['label']), $this->owner, $this->dbh->quoteString($alias)); /* Do the insert */ $r = $this->dbh->simpleQuery($query); if ($r == DB_OK) { return true; } /* Fail */ return $this->set_error(sprintf(_("Database error: %s"), DB::errorMessage($r))); }
/** * This method is used to initialize the storage. Halts on error. * * @public */ function init() { phpCAS::traceBegin(); // if the storage has already been initialized, return immediatly if ($this->isInitialized()) { return; } // call the ancestor's method (mark as initialized) parent::init(); //include phpDB library (the test was introduced in release 0.4.8 for //the integration into Tikiwiki). if (!class_exists('DB')) { include_once 'DB.php'; } // try to connect to the database $this->_link = DB::connect($this->getURL()); if (DB::isError($this->_link)) { phpCAS::error('could not connect to database (' . DB::errorMessage($this->_link) . ')'); } var_dump($this->_link); phpCAS::traceBEnd(); }
public function _errorMessage($dbcode) { return DB::errorMessage($dbcode); }
/** * Contructor * * Mail_Queue_Container_db:: Mail_Queue_Container_db() * * @param mixed $options An associative array of option names and * their values. See DB_common::setOption * for more information about connection options. * * @access public */ function Mail_Queue_Container_db($options) { if (!is_array($options) || !isset($options['dsn'])) { return new Mail_Queue_Error(MAILQUEUE_ERROR_NO_OPTIONS, $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__, 'No dns specified!'); } if (isset($options['mail_table'])) { $this->mail_table = $options['mail_table']; } $this->sequence = isset($options['sequence']) ? $options['sequence'] : $this->mail_table; if (!empty($options['pearErrorMode'])) { $this->pearErrorMode = $options['pearErrorMode']; } $this->db =& DB::connect($options['dsn'], true); if (DB::isError($this->db)) { return new Mail_Queue_Error(MAILQUEUE_ERROR_CANNOT_CONNECT, $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__, 'DB::connect failed: ' . DB::errorMessage($this->db)); } else { $this->db->setFetchMode(DB_FETCHMODE_ASSOC); } $this->setOption(); }
/** * this function returns the kind of Error * * @author * * @access public * @param string $code * @return string * */ public function errorMessage($code) { static $gErrorMessages; if ($code < 0 && $code > -100) { return DB::errorMessage($code); } else { if (!isset($gErrorMessages)) { $gErrorMessages = array(G_ERROR => 'unknown error', DB_ERROR_FEATURE_NOT_AVAILABLE => 'this function or feature is not available for this database engine', DB_ERROR_OBJECT_NOT_DEFINED => 'Object or variable not defined', G_ERROR_WARNING_MESSAGE => 'Warning message'); } /* if (DB::isError($code)) { $code = $code->getCode(); } */ return isset($gErrorMessages[$code]) ? $gErrorMessages[$code] : (isset($errorMessages) ? $errorMessages['G_ERROR'] : ''); } }
function garbageCollection($maxlifetime) { $this->flushPreload(); $query = sprintf('DELETE FROM %s WHERE (expires <= %d AND expires > 0) OR changed <= %d', $this->cache_table, time(), time() - $maxlifetime); $res = $this->db->query($query); $query = sprintf('select sum(length(cachedata)) as CacheSize from %s', $this->cache_table); $cachesize = $this->db->GetOne($query); if (DB::isError($cachesize)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($cachesize), __FILE__, __LINE__); } //if cache is to big. if ($cachesize > $this->highwater) { //find the lowwater mark. $query = sprintf('select length(cachedata) as size, changed from %s order by changed DESC', $this->cache_table); $res = $this->db->query($query); if (DB::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); } $numrows = $this->db->numRows($res); $keep_size = 0; while ($keep_size < $this->lowwater && $numrows--) { $entry = $res->fetchRow(DB_FETCHMODE_ASSOC); $keep_size += $entry['size']; } //delete all entries, which were changed before the "lowwwater mark" $query = sprintf('delete from %s where changed <= ' . ($entry['changed'] ? $entry['changed'] : 0), $this->cache_table); $res = $this->db->query($query); } if (DB::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); } }
$result = $connection->query($query); if (DB::isError($result)) { die("Could not query the database: <br />" . $query . " " . DB::errorMessage($result)); } echo "Posted successfully.<br />"; $stop = TRUE; } if ($_POST['action'] == "edit" and !$stop) { $title = mysql_real_escape_string(get_magic_quotes_gpc() ? stripslashes($title) : $title); $body = mysql_real_escape_string(get_magic_quotes_gpc() ? stripslashes($body) : $body); $comment_id = mysql_real_escape_string(get_magic_quotes_gpc() ? stripslashes($comment_id) : $comment_id); $user_id = mysql_real_escape_string(get_magic_quotes_gpc() ? stripslashes($user_id) : $user_id); $query = "UPDATE comments SET title='" . $title . "',body='" . $body . "'\nWHERE comment_id='" . $comment_id . "' AND user_id='" . $user_id . "'"; $result = $connection->query($query); if (DB::isError($result)) { die("Could not query the database: <br />" . $query . " " . DB::errorMessage($result)); } echo 'Updated successfully.<br />'; $stop = TRUE; } } if (!$stop) { // Display blank form // Create an empty entry $post_id = $_GET["post_id"]; $result_row = array('title' => NULL, 'body' => NULL, 'comment_id' => NULL); $comments[] = $result_row; // Get the categories $smarty->assign('post_id', htmlentities($post_id)); $smarty->assign('comments', $comments); $smarty->assign('action', 'add');
/** * This method is used to initialize the storage. Halts on error. * * @public */ function init() { phpCAS::traceBegin(); // if the storage has already been initialized, return immediatly if ($this->isInitialized()) { return; } // call the ancestor's method (mark as initialized) parent::init(); // try to connect to the database $this->_link = DB::connect($this->getURL()); if (DB::isError($this->_link)) { phpCAS::error('could not connect to database (' . DB::errorMessage($this->_link) . ')'); } var_dump($this->_link); phpCAS::traceBEnd(); }
/** * DB_Warning constructor. * * @param $code mixed DB error code, or string with error message. * @param $mode int what "error mode" to operate in * @param $level what error level to use for $mode == PEAR_ERROR_TRIGGER * @param $debuginfo additional debug info, such as the last query * * @access public * * @see PEAR_Error */ public function DB_Warning($code = DB_WARNING, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE, $debuginfo = null) { if (is_int($code)) { $this->PEAR_Error('DB Warning: ' . DB::errorMessage($code), $code, $mode, $level, $debuginfo); } else { $this->PEAR_Error("DB Warning: {$code}", 0, $mode, $level, $debuginfo); } }
} $from = isset($_GET['from']) ? (int) $_GET['from'] : 0; $limit = 1; $pager = new DB_Pager($res, $from, $limit); $data = $pager->build(); if (DB::isError($data)) { die(DB::errorMessage($data)); } while ($row = $pager->fetchRow(DB_FETCHMODE_ASSOC)) { $pc = explode(" ", $row['Postcode']); $intOSX = $row["osx"]; $intOSY = $row["osy"]; $SQLTrans = "SELECT places.place_ID, places.place_type, places.place_title, places.place_desc, places.place_osx, places.place_osy, pl_type.pl_type_id, pl_type_title FROM places, pl_type WHERE (places.place_type = 1 OR places.place_type = 2) AND places.place_type = pl_type.pl_type_id ORDER BY sqrt((abs(places.place_osx-" . $intOSX . ")*abs(places.place_osx-" . $intOSX . "))+(abs(places.place_osy-" . $intOSY . ")*abs(places.place_osy-" . $intOSY . "))) LIMIT 1"; $rowTrans = $con->getRow($SQLTrans, DB_FETCHMODE_ASSOC); if (DB::isError($resTrans = $con->query($SQLTrans))) { die(DB::errorMessage($resTrans)); } $intTransType = $rowTrans['place_type']; $strTransType = $rowTrans['pl_type_title']; $strTransTitle = $rowTrans['place_title']; $strTransDesc = $rowTrans['place_desc']; $intTransOSX = $rowTrans['place_osx']; $intTransOSY = $rowTrans['place_osy']; if ($strTransType == "Station") { $strTransType = "trains"; } $intTransDistance = round(sqrt(abs($intTransOSX - $intOSX) * abs($intTransOSX - $intOSX) + abs($intTransOSY - $intOSY) * abs($intTransOSY - $intOSY))); if ($intTransType == 1) { $strTrans = '<img src="http://www.woosterstock.co.uk/images/mapping/rail.gif" width="17" height="10" align="absmiddle"> <b>' . $strTransTitle . '</b><br><font color="#666666">(approx. ' . $intTransDistance . ' meters)</font>'; } elseif ($intTransType == 2) { $strTrans = '<img src="http://www.woosterstock.co.uk/images/mapping/tube.gif" width="12" height="10" align="absmiddle"> <b>' . $strTransTitle . '</b><br><font color="#666666">(approx. ' . $intTransDistance . ' meters)</font>';
/** * @param \PEAR_Exception $e * An unhandled exception. * @param array $apiRequest * The full description of the API request. * @return array * API response. */ public function formatPearException($e, $apiRequest) { $data = array(); $error = $e->getCause(); if ($error instanceof \DB_Error) { $data["error_code"] = \DB::errorMessage($error->getCode()); $data["sql"] = $error->getDebugInfo(); } if (!empty($apiRequest['params']['debug'])) { if (method_exists($e, 'getUserInfo')) { $data['debug_info'] = $error->getUserInfo(); } if (method_exists($e, 'getExtraData')) { $data['debug_info'] = $data + $error->getExtraData(); } $data['trace'] = $e->getTraceAsString(); } else { $data['tip'] = "add debug=1 to your API call to have more info about the error"; } return $this->createError($e->getMessage(), $data, $apiRequest); }
/** * Maps a DB error code to a textual message * * @param integer $dbcode the DB error code * * @return string the error message corresponding to the error code * submitted. FALSE if the error code is unknown. * * @see DB::errorMessage() */ function errorMessage($dbcode) { return DB::errorMessage($this->errorcode_map[$dbcode]); }
printf('<a href="%s?letter=%s">%s</a> ', htmlspecialchars($_SERVER['PHP_SELF']), $fl, strtoupper($fl)); } } print '</td><td rowspan="2" align="right">'; print '<form><input type="button" onclick="'; $gourl = "http://" . $_SERVER['SERVER_NAME']; if ($_SERVER['SERVER_PORT'] != 80) { $gourl .= ":" . $_SERVER['SERVER_PORT']; } $gourl .= "/user/"; print "u=prompt('Go to account:','');if(u)location.href='{$gourl}'+u;"; print '" value="Go to account.." /></td></tr><tr><td>'; printf("Displaying accounts %d - %d of %d<br />\n", $offset, min($offset + $show, $naccounts), $naccounts); $sth = $dbh->limitQuery('SELECT handle,name,email,homepage,showemail ' . 'FROM users WHERE registered = 1 ORDER BY handle', $offset, $show); if (DB::isError($sth)) { die("query failed: " . DB::errorMessage($dbh) . "<br />\n"); } print "</td></tr></table>\n"; print "</td>\n"; print " <th>"; if ($offset + $page_size < $naccounts) { $nn = min($page_size, $naccounts - $offset - $page_size); print "<a href=\"{$nextlink}\">Next {$nn} >></a>"; } else { print " "; } print "</th>\n"; print " </tr>\n"; print " <tr bgcolor=\"#CCCCCC\">\n"; print " <th>Handle</th>\n"; print " <th>Name</th>\n";