public static function simpleXPath($xpath, \DOMDocument $dom, array $ns = array()) { $xp = new self($dom); foreach ($ns as $prefix => $uri) { $xp->registerNamespace($prefix, $uri); } return $xp->query($xpath); }
public static function getAll($stmt) { $db = new self(); $res = $db->query($stmt); $ret = array(); while ($row = mysql_fetch_assoc($res)) { $ret[] = $row; } return $ret; }
public static function doPings($srv_uri, $site_name, $site_url) { $o = new self($srv_uri); $o->timeout = 3; $rsp = $o->query('weblogUpdates.ping', $site_name, $site_url); if (isset($rsp['flerror']) && $rsp['flerror']) { throw new Exception($rsp['message']); } return true; }
/** * @author chenliujin <*****@*****.**> * @since 2016-09-21 */ public function get_category_tree() { $language_id = $_SESSION['languages_id']; $sql = "\n\t\t\tSELECT categories.categories_id, categories_name, parent_id \n\t\t\tFROM " . self::getTableName() . ", " . categories_description::getTableName() . " \n\t\t\tWHERE categories.categories_id = categories_description.categories_id\n\t\t \t\tAND language_id = " . (int) $language_id . "\n\t\t\t\tAND categories_status = 1\n\t\t\tORDER BY parent_id, sort_order, categories_name\n\t\t\t"; $_this = new self(); $rs = $_this->query($sql); foreach ($rs as $category) { $category->path = !$category->parent_id ? 'cPath=' . $category->categories_id : self::$data[$category->parent_id]->path . '_' . $category->categories_id; self::$data[$category->categories_id] = $category; if (!$category->parent_id) { self::$root[$category->categories_id] = $category; } else { self::$data[$category->parent_id]->children[] = $category->categories_id; } } }
public function copy($where, array $newArgs) { $db = new self($this->db, $this->table); $rows = $db->query($where)->exec(); if (!empty($rows)) { foreach ($rows as $row) { unset($row['id']); unset($row['created_at']); unset($row['updated_at']); $db->create(array_merge($row, $newArgs))->save(); } } return $this; }
/** * A static function designed to make it easier to get the info * * @static * @access public * * @param string $query * @param mixed $context * @param array|Traversable $ret - passed by reference * * @return array */ public static function find($query, $context, $ret = null) { $new = array(); //query using DOMDocument if ($context instanceof DOMDocument) { $css = new self($context); $new = $css->query($query); } elseif ($context instanceof DOMNodeList) { if ($context->length) { $css = new self($context->item(0)->ownerDocument); $new = $css->query($query, $context); } } elseif (!$context instanceof DOMNode && count($context)) { $css = new self($context[0]->ownerDocument); $new = $css->query($query, $context); } else { $css = new self($context->ownerDocument); $new = $css->query($query, $context); } //if there is a place to store the newly selected elements if ($ret) { //append the newly selected elements to the given array|object //or if it is an instance of ArrayAccess just push it on to the object if (is_array($ret)) { $new = array_merge($ret, $new); $new = self::unique($new); $ret = $new; } elseif (is_object($ret)) { if ($ret instanceof ArrayAccess) { foreach ($new as $elem) { $ret[count($ret)] = $elem; } } elseif ($ret instanceof DOMDocumentFragment) { foreach ($new as $elem) { //appendChild, but don't forget to verify same document $ret->appendChild(!$ret->ownerDocument->isSameNode($elem->ownerDocument) ? $ret->ownerDocument->importNode($elem, true) : $elem); } } elseif (($m = method_exists($ret, 'push')) || method_exists($ret, 'add')) { $method = $m ? 'push' : 'add'; foreach ($new as $elem) { $ret->{$method}($elem); } } elseif (($m = method_exists($ret, 'concat')) || method_exists($ret, 'concatenate')) { $method = $m ? 'concat' : 'concatenate'; $ret->{$method}($new); } } elseif (is_string($ret)) { foreach ($new as $elem) { $ret .= $elem->ownerDocument->saveXML($elem); } } } return $new; }
public static function logMotivation($userId, $time, $activityId, $firstName, $lastName, $duration, $goal, $percentage, $activityName, $message) { //Anonymous db $db = new self(0); $message = $db->cleanForDb($message); $logQuery = 'INSERT INTO motivation '; $logQuery .= ' (user_id, time, activity_id, first_name, last_name, duration, goal, percentage, activity_name, message) '; $logQuery .= ' VALUES '; $logQuery .= " ({$userId}, '{$time}', {$activityId}, '{$firstName}', '{$lastName}', {$duration}, {$goal}, {$percentage}, '{$activityName}', '{$message}');"; return $db->query($logQuery); }
/** * Delete all by user_id * * @param $user_id */ public static function deleteAllByUser($user_id) { $obj = new self(); $sql = 'DELETE * FROM `' . $obj->table . '` WHERE user_id = ' . $user_id; $obj->query($sql); }
public function dropcache() { global $dbdata; $ldb = new self(); $istab = $this->query("SHOW TABLES WHERE Tables_in_{$dbdata} like '#__cache_%'"); while ($x = $this->get()) { $ldb->query("DROP TABLE {$x['Tables_in_' . $dbdata]}"); } }
/** * Test if the specified language is supported by sending a request to google * * @param string $language * @return boolean */ public static function testAvailableLanguage($language) { $adapter = new self(); if (extension_loaded('curl')) { $adapter->setRequestType('curl'); } else { $adapter->setRequestType('http'); } if (!self::isAvailableLanguage($language)) { return false; } try { $adapter->query('en', $language, 'test'); } catch (Exception $e) { var_dump($e->__toString()); return false; } return true; }
public static function get($new_connection = false) { if (!isset(self::$config)) { self::$config = server_get_config(); } if (!db::$connection || $new_connection) { $db = new self(self::$config['db_server'], self::$config['db_username'], self::$config['db_password'], self::$config['db_database'], self::$config['db_port']); if (mysqli_connect_error()) { throw new Exception(sprintf('Could not connect to database server. Error received: %s', mysqli_connect_error()), MYSQL_CONNECT_ERROR); } if (!$db->set_charset('utf8')) { throw new Exception('Could not change MySQL character-set. Check your MySQL user credentials'); } if (!$db->set_time_zone()) { throw new Exception('Could not change MySQL time-zone. Check your MySQL user credentials'); } if (isset(self::$config['mysql_big_selects']) && self::$config['mysql_big_selects'] === true) { if (!$db->enable_compat_mode()) { throw new Exception('Could not change MYSQL compatbility options. Check your MySQL user permissions.'); } } $db->query("SET SESSION sql_mode = ''"); if ($new_connection) { return $db; } db::$connection = $db; } return db::$connection; }
/** * Деструктор. Закрывает открытую транзакцию и записывает в файл(ы) debug информацию. */ public function __destruct() { --self::$objects; if ($this->debugLog) { $log = new log('db/' . $this->alias . '/debug/' . $this->debug); for ($i = 0; $i < count($this->debugLog); ++$i) { $log->writeln($this->debugLog[$i]['text']); } } $log = new log('db/' . $this->alias . '/' . date('Y-m-d') . '.log'); if ($this->log) { $log->writeln($this->log); } if ($this->_transaction) { $rollback = false; $xstat = pg_transaction_status($this->_transaction); $xcodes = array(PGSQL_TRANSACTION_UNKNOWN => 'PGSQL_TRANSACTION_UNKNOWN', PGSQL_TRANSACTION_IDLE => 'PGSQL_TRANSACTION_IDLE', PGSQL_TRANSACTION_INTRANS => 'PGSQL_TRANSACTION_INTRANS', PGSQL_TRANSACTION_INERROR => 'PGSQL_TRANSACTION_INERROR', PGSQL_TRANSACTION_ACTIVE => 'PGSQL_TRANSACTION_ACTIVE'); switch ($xstat) { case PGSQL_TRANSACTION_INTRANS: case PGSQL_TRANSACTION_INERROR: case PGSQL_TRANSACTION_ACTIVE: $rollback = true; break; } if ($rollback) { $err = "Transaction status is BAD and it rollbacked: {$xcodes[$xstat]}, name=" . $this->alias; $this->rollback(); } else { $err = "Transaction counter is BAD on DESTRUCT: status {$xcodes[$xstat]}"; $this->_transaction = null; } $this->err($err); } if (!self::$objects) { setLastUserAction(); if (self::$_stby_log) { // можно убрать, отладочное. $stby_db = new self('stat'); setlocale(LC_ALL, 'en_US.UTF-8'); foreach (self::$_stby_log as $key => $val) { list($val['day'], $val['real_mask'], $val['opts']) = explode('=', $key); $sql = ' UPDATE stby_log2 SET master_cnt = master_cnt + ?i, standby_cnt = standby_cnt + ?i, master_time = master_time + interval ?, standby_time = standby_time + ?, ro_errors_cnt = ro_errors_cnt + ?i WHERE day = ? AND opts = ? AND real_mask = ?i '; $res = $stby_db->query($sql, (int) $val['master_cnt'], (int) $val['standby_cnt'], (double) $val['master_time'] . ' seconds', (double) $val['standby_time'] . ' seconds', (int) $val['ro_errors_cnt'], $val['day'], $val['opts'], (int) $val['real_mask']); if (!pg_affected_rows($res)) { $sql = ' INSERT INTO stby_log2 (master_cnt, standby_cnt, master_time, standby_time, ro_errors_cnt, day, opts, real_mask) VALUES (?i, ?i, ?, ?, ?i, ?, ?, ?i) '; $stby_db->query($sql, (int) $val['master_cnt'], (int) $val['standby_cnt'], (double) $val['master_time'] . ' seconds', (double) $val['standby_time'] . ' seconds', (int) $val['ro_errors_cnt'], $val['day'], $val['opts'], (int) $val['real_mask']); } } } self::$_stby_log = array(); } }
/** * Returns an instance of this object by it's id * @param integer $id * @return \Mojavi\Form\MongoForm */ public static function retrieveById($id) { if (apc_exists(__CLASS__ . '_' . $id)) { $ret_val = apc_fetch(__CLASS__ . '_' . $id); return $ret_val; } $obj = new self(); $obj->setId($id); $obj->query(); apc_add(__CLASS__ . '_' . $id, $obj); return $obj; }