Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 KB | None | 0 0
  1.         function changePassword($newPassword) {
  2.             $db = Loader::db();
  3.             if ($this->uID) {
  4.                 $v = array(User::encryptPassword($newPassword), $this->uID);
  5.                 $q = "update Users set uPassword = ? where uID = ?";
  6.                 $r = $db->prepare($q);
  7.                 $res = $db->execute($r, $v);
  8.                 Events::fire('on_user_change_password', $this, $newPassword);
  9.                 return $res;
  10.             }
  11.         }
  12.  
  13.         public function db($server = null, $username = null, $password = null, $database = null, $create = false) {
  14.             static $_db;
  15.             if (!isset($_db) || $create) {
  16.                 if ($server == null && defined('DB_SERVER')) { 
  17.                     $dsn = DB_TYPE . '://' . DB_USERNAME . ':' . rawurlencode(DB_PASSWORD) . '@' . rawurlencode(DB_SERVER) . '/' . DB_DATABASE;
  18.                 } else if ($server) {
  19.                     $dsn = DB_TYPE . '://' . $username . ':' . rawurlencode($password) . '@' . rawurlencode($server) . '/' . $database;
  20.                 }
  21.  
  22.                 if (isset($dsn) && $dsn) {
  23.                     $_dba = @NewADOConnection($dsn);
  24.                     if (is_object($_dba)) {
  25.                         $_dba->setFetchMode(ADODB_FETCH_ASSOC);
  26.                         if (DB_CHARSET != '') {
  27.                             $names = 'SET NAMES \'' . DB_CHARSET . '\'';
  28.                             if (DB_COLLATE != '') {
  29.                                 $names .= ' COLLATE \'' . DB_COLLATE . '\'';
  30.                             }
  31.                             $charset = 'SET CHARACTER SET \'' . DB_CHARSET . '\'';
  32.                             if (DB_COLLATE != '') {
  33.                                 $charset .= ' COLLATE \'' . DB_COLLATE . '\'';
  34.                             }
  35.                             $_dba->Execute($names);
  36.                             $_dba->Execute($charset);
  37.                         }
  38.                        
  39.                         ADOdb_Active_Record::SetDatabaseAdapter($_dba);
  40.                         $_db = new Database();
  41.                         $_db->setDatabaseObject($_dba);
  42.                         //$_db->setLogging(true);
  43.                     } else if (defined('DB_SERVER')) {
  44.                         $v = View::getInstance();
  45.                         $v->renderError(t('Unable to connect to database.'), t('A database error occurred while processing this request.'));
  46.                     }
  47.                 } else {
  48.                     return false;
  49.                 }
  50.             }
  51.            
  52.             return $_db;
  53.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement