コード例 #1
0
 function create_backup_sql($file)
 {
     $line_count = 0;
     $db_connection = $this->db_connect();
     mysql_select_db($this->db_name(), $db_connection) or die("ERROR: Unable to connect database (code:m_s_db)");
     $tables = mysql_list_tables($this->db_name());
     $sql_string = NULL;
     while ($table = mysql_fetch_array($tables)) {
         $table_name = $table[0];
         $sql_string = "DELETE FROM {$table_name}";
         $table_query = mysql_query("SELECT * FROM `{$table_name}`");
         $num_fields = mysql_num_fields($table_query);
         while ($fetch_row = mysql_fetch_array($table_query)) {
             $sql_string .= "INSERT INTO {$table_name} VALUES(";
             $first = TRUE;
             for ($field_count = 1; $field_count <= $num_fields; $field_count++) {
                 if (TRUE == $first) {
                     $sql_string .= "'" . mysql_real_escape_string($fetch_row[$field_count - 1]) . "'";
                     $first = FALSE;
                 } else {
                     $sql_string .= ", '" . mysql_real_escape_string($fetch_row[$field_count - 1]) . "'";
                 }
             }
             $sql_string .= ");";
             if ($sql_string != "") {
                 $line_count = $this->write_backup_sql($file, $sql_string, $line_count);
             }
             $sql_string = NULL;
         }
     }
     return $line_count;
 }
コード例 #2
0
 function getMysqlDump()
 {
     mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
     $tables = mysql_list_tables(DB_NAME);
     while ($td = mysql_fetch_array($tables)) {
         $table = $td[0];
         if ($table == $this->_tableName) {
             continue;
         }
         $SQL[] .= "DROP TABLE IF EXISTS `{$table}`;";
         $r = mysql_query("SHOW CREATE TABLE `{$table}`");
         if ($r) {
             $insert_sql = "";
             $d = mysql_fetch_array($r);
             $d[1] .= ";";
             $SQL[] = $d[1];
             $table_query = mysql_query("SELECT * FROM `{$table}`");
             $num_fields = mysql_num_fields($table_query);
             while ($fetch_row = mysql_fetch_array($table_query)) {
                 $insert_sql .= "INSERT INTO {$table} VALUES(";
                 for ($n = 1; $n <= $num_fields; $n++) {
                     $m = $n - 1;
                     $insert_sql .= "\"" . mysql_real_escape_string($fetch_row[$m]) . "\", ";
                     $insert_sql = str_replace("'", "\\'", $insert_sql);
                 }
                 $insert_sql = substr($insert_sql, 0, -2);
                 $insert_sql .= ");\n";
             }
             if ($insert_sql != "") {
                 $SQL[] = $insert_sql;
             }
         }
     }
     return implode("\r", $SQL);
 }
コード例 #3
0
function cw_cpanel_check_fields($fields, &$check)
{
    $check = array();
    $check['path'] = is_writable($fields['path']);
    $mylink = @mysql_connect($fields['mysql_host'], $fields['mysql_user'], $fields['mysql_password'], true);
    $check['mysql_host'] = $mylink ? true : false;
    if ($mylink) {
        $check['mysql_database'] = @mysql_select_db($fields['mysql_db'], $mylink) ? true : false;
    }
    if ($check['path']) {
        $check['skins'] = is_dir($fields['path'] . '/skins');
    }
    if ($check['mysql_database']) {
        $res = @mysql_list_tables($fields['mysql_db'], $mylink);
        $check['tables'] = false;
        while ($row = @mysql_fetch_row($res)) {
            $ctable = $row[0];
            if ($ctable == 'ars_products' || $ctable == 'ars_customers') {
                $check['tables'] = true;
                break;
            }
        }
    }
    @mysql_close($mylink);
    $required_fields = array('path', 'mysql_host', 'mysql_database');
    $is_no_error = true;
    foreach ($required_fields as $val) {
        $is_no_error &= $check[$val];
    }
    return $is_no_error;
}
コード例 #4
0
 function GetTables()
 {
     $xmlOutput = "";
     $result = mysql_list_tables($this->database, $this->connectionId);
     if ($result) {
         $xmlOutput = "<RESULTSET><FIELDS>";
         // Columns are referenced by index, so Schema and
         // Catalog must be specified even though they are not supported
         $xmlOutput .= "<FIELD><NAME>TABLE_CATALOG</NAME></FIELD>";
         // column 0 (zero-based)
         $xmlOutput .= "<FIELD><NAME>TABLE_SCHEMA</NAME></FIELD>";
         // column 1
         $xmlOutput .= "<FIELD><NAME>TABLE_NAME</NAME></FIELD>";
         // column 2
         $xmlOutput .= "</FIELDS><ROWS>";
         $tableCount = mysql_num_rows($result);
         for ($i = 0; $i < $tableCount; $i++) {
             $xmlOutput .= "<ROW><VALUE/><VALUE/><VALUE>";
             $xmlOutput .= mysql_tablename($result, $i);
             $xmlOutput .= "</VALUE></ROW>";
         }
         $xmlOutput .= "</ROWS></RESULTSET>";
     }
     return $xmlOutput;
 }
コード例 #5
0
ファイル: mysqlConnector.php プロジェクト: fmlyhm/AndroidRAT
 public function Sorgu($Sorgum, $Secim = "0", $FF = null)
 {
     $this->DBCon = mysql_connect($this->DBServer, $this->DBUser, $this->DBUserPass) or die('MySQL connect failed. ' . mysql_error());
     mysql_select_db($this->DBName, $this->DBCon);
     switch ($Secim) {
         case "0":
             return mysql_query($Sorgum);
             break;
         case "1":
             $Al = mysql_query($Sorgum);
             return @mysql_fetch_array($Al, MYSQL_NUM);
             break;
         case "2":
             $Al = mysql_query($Sorgum);
             return mysql_num_rows($Al);
             break;
         case "3":
             $Al = @mysql_list_tables($this->DataBaseAdi);
             return mysql_fetch_array($Al);
             break;
         case "4":
             $Al = @mysql_query($Sorgum);
             return mysql_fetch_assoc($Al);
             break;
         case "5":
             $Al = @mysql_query($Sorgum);
             return mysql_fetch_array($Al);
             break;
         default:
             break;
     }
 }
コード例 #6
0
function dumpData($link, $mdb_name, $live_link)
{
    $result = mysql_list_tables($mdb_name, $link);
    while ($row = mysql_fetch_row($result)) {
        $getdata = mysql_query("SELECT * FROM {$row['0']}", $link);
        while ($row1 = mysql_fetch_array($getdata)) {
            $thesql = "INSERT INTO `{$row['0']}` VALUES (";
            $getcols = mysql_list_fields($mdb_name, $row[0], $link);
            for ($c = 0; $c < mysql_num_fields($getcols); $c++) {
                $thesql .= "'" . mysql_format($row1[$c]) . "'";
                if ($c < mysql_num_fields($getcols) - 1) {
                    $thesql .= ",";
                }
            }
            $thesql .= ")";
            mysql_query("{$thesql}", $live_link);
            unset($err);
            $err = mysql_error();
            if ($err) {
                print "Query: " . $tok . "<br>";
                print "Error: " . $err . "<br>";
            } else {
                print ".";
                ob_flush();
                flush();
            }
            $thesql = "";
        }
    }
    return true;
}
コード例 #7
0
ファイル: dbbackup.php プロジェクト: BerlusGmbH/Berlussimo
function create_backup($file)
{
    $line_count = 0;
    $tables = mysql_list_tables(DB_NAME);
    $sql_string = NULL;
    while ($table = mysql_fetch_array($tables)) {
        $table_name = $table[0];
        $sql_string = "\nTRUNCATE {$table_name};\n";
        $table_query = mysql_query("SELECT * FROM `{$table_name}`");
        $num_fields = mysql_num_fields($table_query);
        while ($fetch_row = mysql_fetch_array($table_query)) {
            $sql_string .= "INSERT INTO {$table_name} VALUES(";
            $first = TRUE;
            for ($field_count = 1; $field_count <= $num_fields; $field_count++) {
                if (TRUE == $first) {
                    $sql_string .= "'" . mysql_real_escape_string($fetch_row[$field_count - 1]) . "'";
                    $first = FALSE;
                } else {
                    $sql_string .= ", '" . mysql_real_escape_string($fetch_row[$field_count - 1]) . "'";
                }
            }
            $sql_string .= ");";
            if ($sql_string != "") {
                $line_count = write_backup($file, $sql_string, $line_count);
            }
            $sql_string = NULL;
        }
    }
    return $line_count;
}
コード例 #8
0
function load_db_dump($file, $sqlserver, $user, $pass, $dest_db)
{
    $sql = mysql_connect($sqlserver, $user, $pass);
    $result = mysql_list_tables($dest_db);
    while ($table = mysql_fetch_array($result)) {
        $query = "DROP TABLE `" . $table[0] . "`";
        mysql_query($query);
    }
    $a = file($file);
    foreach ($a as $n => $l) {
        if (substr($l, 0, 2) == '--') {
            unset($a[$n]);
        }
    }
    $a = explode(";\n", implode("\n", $a));
    unset($a[count($a) - 1]);
    foreach ($a as $q) {
        if ($q) {
            if (!mysql_query($q)) {
                mysql_close($sql);
            }
        }
    }
    mysql_close($sql);
    header("Location: " . BASE_URL);
}
コード例 #9
0
function optimaliseer()
{
    global $sql;
    $tabellen = mysql_list_tables($sql['db']);
    $totaal = 0;
    echo "Size of the Tables:<br /><br />\n        <table width=\"600\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">\n        <tr>\n            <td width=\"200\"><strong>TABLE</strong></td>\n            <td width=\"200\"><strong>BEFORE</STRONG></td>\n            <td width=\"200\"><strong>AFTER</strong></td>\n        </tr>";
    while ($tabel_naam = mysql_fetch_row($tabellen)) {
        $grootte1 = 0;
        $grootte2 = 0;
        $query1 = mysql_query("SHOW TABLE STATUS FROM " . $sql['db'] . " LIKE '" . $tabel_naam[0] . "'") or die(mysql_error());
        mysql_query("OPTIMIZE TABLE " . $tabel_naam[0]) or die(mysql_error());
        $query2 = mysql_query("SHOW TABLE STATUS FROM " . $sql['db'] . " LIKE '" . $tabel_naam[0] . "'") or die(mysql_error());
        while ($data1 = mysql_fetch_assoc($query1)) {
            $grootte1 = $grootte1 + floatval($data1["Data_length"]) + floatval($data1["Index_length"]);
        }
        while ($data2 = mysql_fetch_assoc($query2)) {
            $grootte2 = $grootte2 + floatval($data2["Data_length"]) + floatval($data2["Index_length"]);
        }
        echo "<tr><td>" . $tabel_naam[0] . "</td>";
        echo "<td>" . $grootte1 . " bytes</td>";
        echo "<td>" . $grootte2 . " bytes</td></tr>";
        $totaal += $grootte1 - $grootte2;
        mysql_free_result($query1);
        mysql_free_result($query2);
    }
    echo "</tr></table><br /><br />";
    echo "Space Saved " . $totaal . " bytes.";
}
コード例 #10
0
function makedump($table_select, $what, $db, $crlf = "\n")
{
    global $dump_buffer, $tmp_buffer;
    $tables = mysql_list_tables($db);
    $num_tables = mysql_numrows($tables);
    $dump_buffer = '';
    $tmp_buffer = '';
    $i = 0;
    while ($i < $num_tables) {
        $table = mysql_tablename($tables, $i);
        if (!isset($table_select[$table])) {
            $i++;
            continue;
        }
        if ($what != 'dataonly') {
            $dump_buffer .= PMA_getTableDef($db, $table, $crlf) . ';' . $crlf . $crlf;
        }
        if ($what == 'data' || $what == 'dataonly') {
            $tmp_buffer = '';
            PMA_getTableContent($db, $table, 0, 0, 'PMA_myHandler', $crlf);
            $dump_buffer .= $tmp_buffer . $crlf;
        }
        $i++;
    }
    return $dump_buffer;
}
コード例 #11
0
ファイル: class.database.php プロジェクト: yuantw/Shine
 public function databaseSelected()
 {
     if (!$this->isConnected()) {
         return false;
     }
     $result = mysql_list_tables($this->name, $this->db);
     return is_resource($result);
 }
コード例 #12
0
ファイル: mysqlClass.php プロジェクト: fatfox21/rockoademo
 public function getalltable_old()
 {
     @($result = mysql_list_tables($this->basename));
     while ($row = mysql_fetch_row($result)) {
         $arr[] = $row[0];
     }
     return $arr;
 }
コード例 #13
0
 function list_tables()
 {
     $res = mysql_list_tables($this->db['dbName']);
     for ($i = 0; $i < $this->num_rows($res); $i++) {
         $fields[$i] = mysql_tablename($res, $i);
     }
     return $fields;
 }
コード例 #14
0
ファイル: mysql.php プロジェクト: PapaKot/Horowitz
 function getTables()
 {
     $res = mysql_list_tables($this->db, $this->conn);
     if (!$res) {
         throw new Exception(mysql_error(), EXCEPTION_MYSQL);
     }
     return $res;
 }
コード例 #15
0
function db_list_tables($error_checking = true)
{
    global $MySQL;
    $res = mysql_list_tables($MySQL->db);
    if ($error_checking && !$res) {
        genMySQLErr('Database list tables failed');
    }
    return $res;
}
コード例 #16
0
ファイル: export_db.php プロジェクト: lee99/tpmaker
 function list_tables($database)
 {
     $rs = mysql_list_tables($database);
     $tables = array();
     while ($row = mysql_fetch_row($rs)) {
         $tables[] = $row[0];
     }
     mysql_free_result($rs);
     return $tables;
 }
コード例 #17
0
/**
 * Function: CheckTableExists
 * Purpose: Returns true if the table exists.  False if not
 */
function CheckTableExists($table_name)
{
    $result = mysql_list_tables($GLOBALS[dbname]);
    while ($row = mysql_fetch_row($result)) {
        if ($row[0] == "{$GLOBALS['prefix']}_{$table_name}") {
            return true;
        }
    }
    return false;
}
コード例 #18
0
ファイル: dbbak.php プロジェクト: ekdd1987/panda
 function _getTableList($dbName)
 {
     $tableList = array();
     $result = mysql_list_tables($dbName, $this->_mysql_link_id);
     for ($i = 0; $i < mysql_num_rows($result); $i++) {
         array_push($tableList, mysql_tablename($result, $i));
     }
     mysql_free_result($result);
     return $tableList;
 }
コード例 #19
0
function mysql_table_exists($table, $db)
{
    $tables = mysql_list_tables($db);
    while (list($temp) = mysql_fetch_array($tables)) {
        if ($temp == $table) {
            return 1;
        }
    }
    return 0;
}
コード例 #20
0
 function table_exists($table)
 {
     $tables = mysql_list_tables($this->db_name);
     while (list($temp) = mysql_fetch_array($tables)) {
         if ($temp == $table) {
             return true;
         }
     }
     return false;
 }
コード例 #21
0
ファイル: index.php プロジェクト: RGBvision/AVE.cms
function clean_db($name = "", $prefix = "")
{
    echo 1;
    $query = @mysql_list_tables($name);
    while ($row = @mysql_fetch_array($query, MYSQL_NUM)) {
        if (preg_match("/^" . $prefix . "/", $row[0])) {
            @mysql_query("DROP TABLE " . $row[0]);
        }
    }
}
コード例 #22
0
ファイル: setup.php プロジェクト: rodoabad/amxx-bans
 function TableExists($tablename, $db)
 {
     $result = mysql_list_tables($db);
     $rcount = mysql_num_rows($result);
     for ($i = 0; $i < $rcount; $i++) {
         if (mysql_tablename($result, $i) == $tablename) {
             return true;
         }
     }
     return false;
 }
コード例 #23
0
 /**
  * Просмотр таблиц
  * @return ArrayAccess
  */
 private function list_db_tables()
 {
     if ($this->link === false) {
         $this->connect();
     }
     $query_resource = mysql_list_tables($this->db_name, $this->link);
     while ($row = mysql_fetch_array($query_resource)) {
         $table_list[] = $row[0];
     }
     return $table_list;
 }
コード例 #24
0
 function getTables()
 {
     global $MYSQL_SERVER, $MYSQL_USERNAME, $MYSQL_PASSWORD, $MYSQL_DBNAME;
     $result = mysql_list_tables($MYSQL_DBNAME);
     $num_rows = mysql_num_rows($result);
     for ($i = 0; $i < $num_rows; $i++) {
         //here
         $tables[$i] = mysql_tablename($result, $i);
     }
     return $tables;
 }
コード例 #25
0
ファイル: mysqlConnector.php プロジェクト: rawork/colors-life
 public function getTablesList()
 {
     $a = array();
     $this->result['tables_list'] = mysql_list_tables($this->base, $this->connection);
     if ($this->result['tables_list']) {
         while ($row = mysql_fetch_row($this->result['tables_list'])) {
             $a[] = $row;
         }
     }
     return $a;
 }
コード例 #26
0
ファイル: class.sql.php プロジェクト: pankajit/carumba
 function is_table($table)
 {
     global $dbn;
     $this->result = @mysql_list_tables($dbn);
     while ($this->data = @mysql_fetch_row($this->result)) {
         if ($this->data[0] == $table) {
             return true;
         }
     }
     return false;
 }
コード例 #27
0
 function ListTables($db, $cnx)
 {
     $list = array();
     $_res = mysql_list_tables($db, $cnx);
     $i = 0;
     $ntables = $_res ? @mysql_num_rows($_res) : 0;
     while ($i < $ntables) {
         array_push($list, mysql_tablename($_res, $i));
         $i++;
     }
     return $list;
 }
コード例 #28
0
    /**
     * Returns true if the table exists in the database, false otherwise.
     * @param string $database
     * @param string table
     * @return boolean 
     */
    static

    function table_exists($database, $table)
    {
        $tables = mysql_list_tables($db);
        while (list ($temp) = mysql_fetch_array($tables)) {
            if (strtolower($temp) == strtolower($table)) {
                return true;
            }
        }
        return false;
    }
コード例 #29
0
ファイル: DataBase.php プロジェクト: stden/cs-javaphp
 public static function getTables()
 {
     if (is_null(Data::$con)) {
         Data::$con = Data::connectToDB();
     }
     $tables = mysql_list_tables(DB_NAME, Data::$con) or throwServerProblem(207, mysql_error());
     $res = array();
     while ($table = mysql_fetch_array($tables)) {
         $res[] = $table[0];
     }
     return $res;
 }
コード例 #30
0
ファイル: mysqldump.php プロジェクト: Bremaweb/streber-1
 function dump()
 {
     /**
      * Increase time limit for script execution and initializes some variables
      */
     set_time_limit(0);
     $hostname = "";
     if (isset($_SERVER["HTTP_HOST"])) {
         $hostname = $_SERVER["HTTP_HOST"];
     }
     ### IE need specific headers
     #if(getBrowserAgent() == 'IE') {
     #    #header('Content-Disposition: inline; filename="' . $filename . '.' . $ext . '"');
     #    header('Expires: 0');
     #    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     #    header('Pragma: public');
     #}
     ### Builds the dump
     $tables = mysql_list_tables($this->db_name);
     if (!($num_tables = mysql_numrows($tables))) {
         echo "mysql-error:<pre>" . mysql_error() . "</pre>";
         trigger_error("no tables found", E_USER_ERROR);
         exit(0);
     }
     $dump_buffer = "# slim phpMyAdmin MySQL-Dump\n";
     for ($i = 0; $i < $num_tables; $i++) {
         $table_name = mysql_tablename($tables, $i);
         $dump_buffer .= $this->crlf . '#' . $this->crlf . '#' . $this->backquote($table_name) . $this->crlf . '#' . $this->crlf . $this->crlf . $this->getTableDef($table_name) . ';' . $this->crlf . $this->getTableContentFast($table_name);
     }
     $dump_buffer .= $this->crlf;
     ### Displays the dump as gzip-file
     if (function_exists('gzencode')) {
         $filename = $hostname . "_" . $this->db_name . '_' . date("Y-m-d_H:i") . '.gzip';
         $mime_type = 'application/x-gzip';
         ### Send headers
         header('Content-Type: ' . $mime_type);
         header('Content-Disposition: attachment; filename="' . $filename . '"');
         header('Expires: 0');
         header('Pragma: no-cache');
         echo gzencode($dump_buffer);
         # without the optional parameter level because it bugs
     } else {
         $filename = $hostname . "_" . $this->db_name . '_' . date("Y-m-d_H:i") . '.sql';
         ### Send headers
         header('Content-Type: ' . $mime_type);
         header('Content-Disposition: attachment; filename="' . $filename . '"');
         header('Expires: 0');
         header('Pragma: no-cache');
         #trigger_error("gzencode() not defined. Saving backup failed", E_USER_ERROR);
         echo "<pre>" . $dump_buffer . "</pre>";
     }
 }