public function query($query, $unbuffered = 0) { try { // $query = preg_replace('#([^\s,]+)\s*=\s*ANY\s*\(\s*STRING_TO_ARRAY\s*\((.+),\s*\',\'\)\)#i', 'FIND_IN_SET($1, $2)', $query); if ($this->debug) { if ('S' === $query[0] && preg_match('#\\s+LIMIT\\s+(\\d+)\\s*,\\s*(\\d+)#i', $query)) { throw new Poodle_SQL_Exception('MySQL LIMIT syntax not allowed, use ISO syntax "LIMIT x OFFSET y"'); } if (preg_match('#`[a-z0-9_]+`#i', $query)) { throw new Poodle_SQL_Exception('MySQL backtick syntax not allowed, use the ISO syntax'); } mysqli_report(preg_match('#\\s+WHERE\\s+#', $query) ? MYSQLI_REPORT_ALL : MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); } if ('S' === $query[0]) { $query = preg_replace('#\\s+~\\s+#', ' REGEXP ', $query); # ANSI regular expression } $result = $this->real_query($query, $unbuffered); } catch (mysqli_sql_exception $e) { if (!$this->debug || strpos($e->getMessage(), 'index used') === false) { throw new Poodle_SQL_Exception($e->getMessage(), $e->getCode(), $query); } if (strpos($e->getMessage(), 'index used') === false || preg_match('#\\s+WHERE\\s+#', $query)) { Poodle_Debugger::trigger(htmlspecialchars($e->getMessage()), dirname(dirname(__FILE__))); } mysqli_report(MYSQLI_REPORT_OFF); $result = $this->real_query($query, $unbuffered); mysqli_report(MYSQLI_REPORT_ERROR); } return $result; }
public static function file_write($file, &$content) { $file = Poodle::$DIR_CACHE . $file; if (!is_dir(dirname($file))) { Poodle_Debugger::trigger('Directory "' . dirname($file) . '" doesn\'t exist', dirname(__FILE__)); return false; } if (!($fp = fopen($file, 'wb'))) { return false; } flock($fp, LOCK_EX); if (fwrite($fp, $content) === false) { flock($fp, LOCK_UN); return false; } flock($fp, LOCK_UN); if (!fclose($fp)) { return false; } // Poodle::chmod($file); return true; }
function __get($key) { if ('prefix' === $key) { return $this->prefix; } if (isset($this->tables[$key])) { return $this->tables[$key]; } if (class_exists('Poodle_Debugger', false)) { Poodle_Debugger::trigger('Unknown database table: ' . $key, dirname(__FILE__)); } else { trigger_error('Unknown database table: ' . $key); } return $this->prefix . $key; }