Example #1
0
 public function createTable($maxTableId)
 {
     if ($maxTableId) {
         return DatabaseUtil::cloneTable($this->getTableName(), $this->getTableName($maxTableId));
     } else {
         return false;
     }
 }
Example #2
0
 private function collect()
 {
     $s = Ibos::app()->setting->toArray();
     $serverinfo = PHP_OS . " / PHP v" . PHP_VERSION;
     $serverinfo .= @ini_get("safe_mode") ? " Safe Mode" : null;
     $serversoft = $_SERVER["SERVER_SOFTWARE"];
     $param = array("snkey" => $s["config"]["security"]["authkey"], "url" => $s["siteurl"], "name" => isset($s["unit"]["shortname"]) ? urlencode($s["unit"]["shortname"]) : "", "sitename" => isset($s["unit"]["fullname"]) ? urlencode($s["unit"]["fullname"]) : "", "sys" => $serverinfo, "soft" => $serversoft, "dbver" => Ibos::app()->db->getServerVersion(), "dbsize" => DatabaseUtil::getDatabaseSize(), "path" => $_SERVER["SCRIPT_FILENAME"], "licence" => sprintf("LIMIT:%s|VER:%s|STIME:%s|ETIME:%s", LICENCE_LIMIT, defined("LICENCE_VER") ? LICENCE_VER : "", defined("LICENCE_STIME") ? LICENCE_STIME : "", defined("LICENCE_ETIME") ? LICENCE_ETIME : ""), "contactman" => Ibos::app()->user->realname, "tel" => Ibos::app()->user->mobile, "email" => Ibos::app()->user->email);
     $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 10);
     $url = self::COLLECT_URL . "&k=" . base64_encode(http_build_query($param));
     $curl = curl_init($url);
     if (curl_setopt_array($curl, $options)) {
         curl_exec($curl);
     }
     curl_close($curl);
 }
Example #3
0
 public function actionOptimize()
 {
     $formSubmit = EnvUtil::submitCheck("dbSubmit");
     if ($formSubmit) {
         $tables = $_POST["optimizeTables"];
         if (!empty($tables)) {
             DatabaseUtil::optimize($tables);
         }
         $this->success(Ibos::lang("Operation succeed", "message"));
     } else {
         $list = DatabaseUtil::getOptimizeTable();
         $totalSize = 0;
         foreach ($list as $table) {
             $totalSize += $table["Data_length"] + $table["Index_length"];
         }
         $data["list"] = $list;
         $data["totalSize"] = $totalSize;
         $this->render("optimize", $data);
     }
 }
Example #4
0
/**
 * 恢复备份的sql文件
 * @param string $id 文件名
 * @return array
 */
function restore($id)
{
    $path = PATH_ROOT;
    if (strstr($path, 'data')) {
        $id = trim(str_replace('data', '', $id), '/');
    }
    $file = urldecode($id);
    $fp = @fopen($file, 'rb');
    if ($fp) {
        $sqlDump = fgets($fp, 256);
        $identify = explode(',', base64_decode(preg_replace("/^# Identify:\\s*(\\w+).*/s", "\\1", $sqlDump)));
        $dumpInfo = array('method' => $identify[3], 'volume' => intval($identify[4]), 'tablepre' => $identify[5], 'dbcharset' => $identify[6]);
        if ($dumpInfo['method'] == 'multivol') {
            $sqlDump .= fread($fp, filesize($file));
        }
        fclose($fp);
    } else {
        if (EnvUtil::getRequest('autorestore', 'G')) {
            return array('success' => 1, 'msg' => Ibos::lang('Database import multivol succeed', 'dashboard.default'));
        } else {
            return array('success' => 0, 'msg' => Ibos::lang('Database import file illegal', 'dashboard.default'));
        }
    }
    $command = Ibos::app()->db->createCommand();
    // 分卷导入
    if ($dumpInfo['method'] == 'multivol') {
        $sqlQuery = StringUtil::splitSql($sqlDump);
        unset($sqlDump);
        $dbCharset = Ibos::app()->db->charset;
        $dbVersion = Ibos::app()->db->getServerVersion();
        foreach ($sqlQuery as $sql) {
            $sql = DatabaseUtil::syncTableStruct(trim($sql), $dbVersion > '4.1', $dbCharset);
            if ($sql != '') {
                $command->setText($sql)->execute();
            }
        }
        $delunzip = EnvUtil::getRequest('delunzip', 'G');
        if ($delunzip) {
            @unlink($file);
        }
        $pattern = "/-({$dumpInfo['volume']})(\\..+)\$/";
        $relacement = "-" . ($dumpInfo['volume'] + 1) . "\\2";
        $nextFile = preg_replace($pattern, $relacement, $file);
        $nextFile = urlencode($nextFile);
        $param = array('op' => 'restore', 'id' => $nextFile, 'autorestore' => 'yes');
        if ($delunzip) {
            $param['delunzip'] = 'yes';
        }
        $msg = Ibos::lang('Database import multivol redirect', 'dashboard.default', array('volume' => $dumpInfo['volume']));
        $url = 'restore.php?' . http_build_query($param);
        if ($dumpInfo['volume'] == 1) {
            return array('type' => 'redirect', 'msg' => $msg, 'url' => $url);
        } elseif (EnvUtil::getRequest('autorestore', 'G')) {
            return array('type' => 'redirect', 'msg' => $msg, 'url' => $url);
        } else {
            return array('success' => 1, 'msg' => Ibos::lang('Database import succeed', 'dashboard.default'));
        }
    } else {
        if ($dumpInfo['method'] == 'shell') {
            // 加载系统生成配置文件
            $config = @(include PATH_ROOT . './system/config/config.php');
            if (empty($config)) {
                throw new NotFoundException(Ibos::Lang('Config not found', 'error'));
            } else {
                $db = $config['db'];
            }
            $query = $command->setText("SHOW VARIABLES LIKE 'basedir'")->queryRow();
            $mysqlBase = $query['Value'];
            $mysqlBin = $mysqlBase == '/' ? '' : addslashes($mysqlBase) . 'bin/';
            shell_exec($mysqlBin . 'mysql -h"' . $db['host'] . ($db['port'] ? is_numeric($db['port']) ? ' -P' . $db['port'] : ' -S"' . $db['port'] . '"' : '') . '" -u"' . $db['username'] . '" -p"' . $db['password'] . '" "' . $db['dbname'] . '" < ' . $file);
            return array('success' => 1, 'msg' => Ibos::lang('Database import succeed', 'dashboard.default'));
        } else {
            return array('success' => 0, 'msg' => Ibos::lang('Database import file illegal', 'dashboard.default'));
        }
    }
}
Example #5
0
 public static function sqlDumpTable($table, $extendIns, $sizeLimit, $useHex = true, $startFrom = 0, $currentSize = 0)
 {
     $offset = self::OFFSET;
     $tableDump = "";
     $command = Ibos::app()->db->createCommand();
     $tableFields = $command->setText("SHOW FULL COLUMNS FROM `{$table}`")->queryAll();
     if (!$tableFields) {
         $useHex = false;
     }
     if (!in_array($table, self::getExceptTables())) {
         $tableDumped = 0;
         $numRows = $offset;
         $firstField = $tableFields[0];
         if ($extendIns == "0") {
             while ($currentSize + strlen($tableDump) + 500 < $sizeLimit * 1000 && $numRows == $offset) {
                 if ($firstField["Extra"] == "auto_increment") {
                     $selectSql = "SELECT * FROM `{$table}` WHERE `{$firstField["Field"]}` > {$startFrom} ORDER BY `{$firstField["Field"]}` LIMIT {$offset}";
                 } else {
                     $selectSql = "SELECT * FROM `{$table}` LIMIT {$startFrom}, {$offset}";
                 }
                 $tableDumped = 1;
                 $numRows = $command->setText($selectSql)->execute();
                 $rows = $command->queryAll();
                 foreach ($rows as $row) {
                     $comma = $t = "";
                     $index = 0;
                     foreach ($row as $value) {
                         $t .= $comma . ($useHex && !empty($value) && (StringUtil::strExists($tableFields[$index]["Type"], "char") || StringUtil::strExists($tableFields[$index]["Type"], "text")) ? "0x" . bin2hex($value) : "'" . addslashes($value) . "'");
                         $comma = ",";
                         $index++;
                     }
                     if (strlen($t) + $currentSize + strlen($tableDump) + 500 < $sizeLimit * 1000) {
                         if ($firstField["Extra"] == "auto_increment") {
                             $startFrom = array_shift($row);
                         } else {
                             $startFrom++;
                         }
                         $tableDump .= "INSERT INTO `{$table}` VALUES ( {$t});\n";
                     } else {
                         self::$complete = false;
                         break 2;
                     }
                 }
             }
         } else {
             while ($currentSize + strlen($tableDump) + 500 < $sizeLimit * 1000 && $numRows == $offset) {
                 if ($firstField["Extra"] == "auto_increment") {
                     $selectSql = "SELECT * FROM `{$table}` WHERE {$firstField["Field"]} > {$startFrom} LIMIT {$offset}";
                 } else {
                     $selectSql = "SELECT * FROM `{$table}` LIMIT {$startFrom}, {$offset}";
                 }
                 $tableDumped = 1;
                 $numRows = $command->setText($selectSql)->execute();
                 $rows = $command->queryAll();
                 if ($numRows) {
                     $t1 = $comma1 = "";
                     foreach ($rows as $row) {
                         $t2 = $comma2 = "";
                         $index = 0;
                         foreach ($row as $value) {
                             $t2 .= $comma2 . ($useHex && !empty($value) && (StringUtil::strExists($tableFields[$index]["Type"], "char") || StringUtil::strExists($tableFields[$index]["Type"], "text")) ? "0x" . bin2hex($value) : "'" . addslashes($value) . "'");
                             $comma2 = ",";
                             $index++;
                         }
                         if (strlen($t1) + $currentSize + strlen($tableDump) + 500 < $sizeLimit * 1000) {
                             if ($firstField["Extra"] == "auto_increment") {
                                 $startFrom = array_shift($row);
                             } else {
                                 $startFrom++;
                             }
                             $t1 .= "{$comma1} ({$t2})";
                             $comma1 = ",";
                         } else {
                             $tableDump .= "INSERT INTO `{$table}` VALUES {$t1};\n";
                             self::$complete = false;
                             break 2;
                         }
                     }
                     $tableDump .= "INSERT INTO `{$table}` VALUES {$t1};\n";
                 }
             }
         }
         self::$startRow = $startFrom;
         $tableDump .= "\n";
     }
     return $tableDump;
 }
Example #6
0
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require_once "DatabaseUtil.php";
//echo 'staring<br>';
$DBobj = new DatabaseUtil();
$DBobj->connectToDB();
//searching from table Coupon
$DBobj->searchFrom_Coupon($_POST['SearchKey']);
?>
<form action="MainForm.php" method="get" accept-charset="UTF-8" align="center">
<input action="MainForm.php" type="submit" name="submit" value="BACK" />
</form>
Example #7
0
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require_once "DatabaseUtil.php";
$DBobj = new DatabaseUtil();
$DBobj->connectToDB();
//inserting valure in table Coupon
$DBobj->insertTo_Coupon($_POST['couponName'], $_POST['couponValue']);
echo 'Status of DB after insertion: <br>';
$DBobj->readFrom_Coupon();
?>
<form action="MainForm.php" method="get" accept-charset="UTF-8" align="center">
<input type="submit" name="submit" value="BACK" />
</form>
Example #8
0
 /**
  * Saves the changes to the value
  */
 public function save()
 {
     $db = DatabaseUtil::db_connect($this->database);
     $db->query('update ' . $this->table . 'set ' . $this->column . ' = ' . $this->value . ' where ID=' . $this->ID);
     $db->close();
 }