/**
  * Do raw SQL query
  * This is delegated to by the sql generating functions (insert, update, delete, select) and can also be called externally
  * @param string $sql SQL to query
  * @param string $query_type, specified when this is being delegated to by insert, update, delete and select
  * @return mixed result of the query: new id on insert, true on successful update/delete, assoc result on select
  *
  * @todo better mysql_fetch_* usage
  */
 public function query($sql, $query_type = null)
 {
     // adding this because i had issues where different instances on the same host had the same
     // link and that link would point to the most recently instantiated database.
     // subsequent queries to the earlier instance would have the more recent database selected
     $sql = squeeze($sql);
     // remove extra spaces
     @mysql_select_db($this->database_name, $this->link);
     $sql = trim($sql);
     Logger::info("query starting [{$sql}]", 'MySQLDatabaseService');
     $this->requesting(array('service' => 'MySQLDatabaseService', 'database' => $this->database_name, 'host' => $this->host, 'username' => $this->username, 'SQL' => $sql));
     $query_result = @mysql_query($sql, $this->link);
     if (mysql_error() != "" || mysql_errno() != 0) {
         // maybe just errno != 0 ?
         $error = mysql_error();
         $errno = mysql_errno();
         throw new MySQLDatabaseException("MySQL Error #{$errno}: {$error} [{$sql}]");
     }
     $this->received(array('result' => print_r($query_result, TRUE)));
     if (!$query_result) {
         return null;
     }
     $result = array();
     if (!$query_type) {
         $query_type = self::determine_query_type($sql);
     }
     switch ($query_type) {
         case 'INSERT':
             $result = mysql_insert_id($this->link);
             break;
         case 'SELECT':
             // TODO: improve this to smartly use other mysql_fetch_* funcs
             while ($row = @mysql_fetch_assoc($query_result)) {
                 $column_names = array_keys($row);
                 $row_data = array();
                 foreach ($column_names as $column_name) {
                     $row_data[] = $row[$column_name];
                 }
                 $result[] = $row;
             }
             break;
         case 'UPDATE':
             $result = true;
             break;
         case 'DELETE':
             $result = true;
             break;
         default:
             throw new InvalidSQLException($sql);
     }
     return $result;
 }
Exemple #2
0
    mkdir($target_dir, 0777);
} else {
    if (!is_writeable($target_dir)) {
        chmode($target_dir, 0777);
    }
}
//Scan Directory
$dir = dir($source_dir);
while ($filename = $dir->read()) {
    $old_file = $source_dir . '/' . $filename;
    if (is_file($old_file)) {
        $ext = explode('.', $filename);
        $ext = strtolower($ext[count($ext) - 1]);
        if (in_array($ext, $allows)) {
            $new_file = $target_dir . '/' . $filename;
            squeeze($old_file, $new_file);
            echo $filename . '<br />' . "\n";
        }
    }
}
$dir->close();
function squeeze($source_file, $target_file)
{
    if (is_file($source_file)) {
        file_put_contents($target_file, js_squeeze(file_get_contents($source_file)));
    } else {
        exit('File not exists');
    }
}
function js_squeeze($s)
{