public static function getFields($db, $database) { importClass('DB_Cate_Mysql_Sql'); importClass('DB_Dict'); $object_database = new DB_DictDatabase(); $object_database->name = $database; $query_t = $db->query(DB_Cate_Mysql_Sql::showTable($database)); while ($row_table = $db->fetchArray($query_t)) { $object_table = new DB_DictTable(); $object_table->tableName = $row_table["Tables_in_" . $database]; $table_status = $db->fetch(DB_Cate_Mysql_Sql::showTableStatus($object_table->tableName)); $object_table->tableDesc = $table_status['Comment']; $query_f = $db->query(DB_Cate_Mysql_Sql::showFieldsInformation($database, $object_table->tableName)); while ($row_field = $db->fetchArray($query_f)) { $object_field = new DB_DictField(); $object_field->fieldName = $row_field['COLUMN_NAME']; $object_field->fieldDesc = $row_field['COLUMN_COMMENT']; $object_field->fieldType = $row_field['COLUMN_TYPE']; $object_field->fieldDefault = $row_field['COLUMN_DEFAULT']; $object_field->fieldIsNull = $row_field['IS_NULLABLE'] == 'NO' ? '否' : '是'; $object_field->fieldIdentity = $row_field['EXTRA'] == 'auto_increment' ? 'yes' : 'no'; $object_field->fieldPrimary = $row_field['COLUMN_KEY'] == 'PRI' ? '是' : '否'; $fieldsList[] = $object_field; unset($object_field); } $object_table->fieldsList = $fieldsList; $tablesList[] = $object_table; //VE($object_table) ; unset($object_table, $fieldsList); } $object_database->tablesList = $tablesList; unset($tablesList); return $object_database; }
public static function getFields($db, $database) { importClass('DB_Cate_SqlServer_Sql'); importClass('DB_Dict'); $object_database = new DB_DictDatabase(); $object_database->name = $database; $query_t = $db->query(DB_Cate_SqlServer_Sql::showTableAndDesc()); while ($row_table = $db->fetchArray($query_t)) { $object_table = new DB_DictTable(); $object_table->tableName = $row_table['tableName']; $object_table->tableDesc = $row_table['tableDesc']; $query_f = $db->query(DB_Cate_SqlServer_Sql::showFieldsInformation($object_table->tableName)); while ($row_field = $db->fetchArray($query_f)) { $object_field = new DB_DictField(); $object_field->fieldName = $row_field['fieldName']; $object_field->fieldDesc = $row_field['fieldDesc']; $object_field->fieldType = $row_field['fieldType'] . '(' . $row_field['fieldTypeLength'] . ')'; $object_field->fieldDefault = $row_field['fieldDefault']; $object_field->fieldIsNull = $row_field['fieldIsnull'] == 'NO' ? 'no' : 'yes'; $object_field->fieldIdentity = $row_field['fieldIdentity'] == 'YES' ? 'yes' : 'no'; $object_field->fieldPrimary = $row_field['fieldPrimary'] == 'PRI' ? 'yes' : 'no'; $fieldsList[] = $object_field; unset($object_field); } $object_table->fieldsList = $fieldsList; $tablesList[] = $object_table; //V($object_table) ; unset($object_table, $fieldsList); } $object_database->tablesList = $tablesList; unset($tablesList); return $object_database; }
public function getRecoverTableFilesID($tableName) { importClass('File'); $content = File::getFileContent($this->getTraceFile()); $mat = '~`' . $tableName . '`\\|(\\d+)\\|[^`]*[^\\|]*\\|(\\d+)~is'; if (preg_match($mat, $content, $m)) { $startid = $m[1]; $endid = $m[2]; } else { if (preg_match('~`' . $tableName . '`\\|(\\d+)\\|~is', $content, $m)) { $startid = $m[1]; $endid = $this->sqlFilesNum; } else { return array(NULL, NULL); } } return array($startid, $endid); }
<?php /** * easy4php * * Class for connecting to database using odbc and performing common operations. * * @copyright Copyright (c) 2008 - 2011 * @link http://www.easy4php.com * @author keshuichong * @version 1.0 */ importClass('DB_Abstract'); class DB_Driver_Odbc_Handler extends DB_Abstract { private $query_num = 0; private $link; public function connect() { $this->link = $this->_config['pconnect'] == 0 ? @odbc_connect($this->_config['dsn'], $this->_config['username'], $this->_config['password'], SQL_CUR_USE_ODBC) : odbc_pconnect($this->_config['dsn'], $this->_config['username'], $this->_config['password'], SQL_CUR_USE_ODBC); if (!$this->link) { $this->halt("Connect to odbc failed"); } } function query($sql) { $query = @odbc_do($this->link, $sql); ++$this->query_num; if (!$query) { $this->halt("Query Error: " . $sql); }
function &loadClass($className, $singleton = false, $params = null, $type = 'lib') { static $_classes = array(); if ($singleton && isset($_classes[$className])) { return $_classes[$className]; } importClass($className, $type); if ($singleton) { $_classes[$className] = new $className($params); return $_classes[$className]; } return new $className($params); }
function getDict() { importClass($this->categoryPath . 'GenDict'); return call_user_func_array($this->categoryPath . 'GenDict::getFields', array($this->db, $this->dbConfig['database'])); }
<?php importClass('DB_Check'); class DB_Driver_Mysql_Check implements DB_Check { public static function begin(&$config) { $chkDriver = self::chkDriver($config); if ($chkDriver !== true) { return array('driver', $chkDriver); } $chkConfig = self::chkConfig($config); if ($chkConfig !== true) { return array('config', $chkConfig); } $chkConnect = self::chkConnect($config); if ($chkConnect !== true) { return array('connect', $chkConnect); } return array(true, $config); } /** * check the configuration. * * @return void */ public static function chkConfig(&$config) { if (empty($config['host'])) { return 'empty_host'; }
<?php /** * easy4php * * check the database * * @copyright Copyright (c) 2013 - 2018 * @link http://www.easy4php.com * @author kuishui * @version 1.0 */ require_once 'init.php'; importClass('DB_Factory'); $dbFac = new DB_Factory($_POST); list($result, $msg) = $dbFac->dbCheck(); if ($result === true) { importClass('File'); $file = md5(implode(',', $_POST)); File::writeFile(TMP . 'config_' . $file . '.php', serialize($msg), 'w'); $return = 'succ|' . $file; } else { $return = 'fail|' . $msg; } header('Content-Type: text/html; charset=gbk'); exit($return); ?>
<?php /** * easy4php * * recover the mysql database from sql. * * @package /lib/DB/Cate/Mysql * @copyright Copyright (c) 2008 - 2011 * @link http://www.easy4php.com * @author keshuichong * @version 1.0 */ importClass('DB_Recover'); class DB_Cate_Mysql_Recover extends DB_Recover { public function recoverAllFiles() { for ($i = 1; $i <= $this->sqlFilesNum; $i++) { $sql = File::getFileContent($this->getFileName($i)); $this->sqlExecute($sql); unset($sql); } return true; } public function recoverTable($table, $startid, $endid) { for ($t = $startid; $t <= $endid; $t++) { $sql = File::getFileContent($this->getFileName($t)); if ($t == $startid && preg_match('~#--Table `' . $table . '` Begin(.*)$~is', $sql, $m)) { $sql = $m[1];
public function begin($startRow = 0, $goOn = 0, $tableId = 0, $fileId = 1, $loop = 0) { importClass('File'); $tablesNum = count($this->bakTables); $content = ''; $this->stepByStep && ($content = $this->readTmpContent()); //V($startRow, $goOn, $tableId, $fileId, $loop); $viewsNum = 0; for ($t = $loop; $t <= $tablesNum; $t++) { $queryTable = $this->setQueryTable($tableId); if ($queryTable === false) { //over //echo '--'.$tableId.'--' ; $content .= "\n#Table End\n\n"; break; } if ($tableId != $t) { $t = $tableId; } else { //另起一张表 $content && ($content .= "\n#Table End\n\n"); $this->writeTrace("{$queryTable}|{$fileId}"); $content .= "#--Table {$queryTable} Begin\n\n"; $content .= "DROP TABLE IF EXISTS {$queryTable};\n"; $createtable = $this->db->query("SHOW CREATE TABLE {$queryTable}"); $create = $this->db->fetchRow($createtable); $content .= $create[1] . ";\n\n"; } if (strlen($content) < $this->bakFileSize * 1024) { $tmp_e = $tablesNum - $viewsNum; if ($t >= $tmp_e) { $tableId++; continue; } $sql = "select * from {$queryTable} limit {$startRow},{$this->offset}"; //echo $sql."\n" ; $result = $this->db->query($sql); $fieldsNum = $this->db->getFieldsNum($result); $rowsNum = $this->db->getRowsNum($result); while ($data = $this->db->fetchRow($result)) { $startRow++; $comma = ""; $content .= "INSERT INTO {$queryTable} VALUES("; for ($i = 0; $i < $fieldsNum; $i++) { $content .= $comma . "'" . $this->db->escapeStr($data[$i]) . "'"; $comma = ","; } $content .= ");\n"; if (strlen($content) >= $this->bakFileSize * 1024) { $this->writeSql($fileId, $content); //$content = '' ; //$fileId++ ; } } if ($rowsNum == $this->offset) { $goOn++; //continue ; } else { $total = $goOn * $this->offset + $rowsNum; $goOn = 0; $this->writeTrace("|{$total}|ok\n"); ++$tableId; $startRow = 0; //continue ; } } else { $this->writeSql($fileId, $content); } if ($this->stepByStep && $this->setQueryTable($tableId)) { $content && $this->writeTmpContent($content); return array($startRow, $goOn, $tableId, $fileId, $t + 1, $this->bakFilePrefix); } } $content && $this->writeSql($fileId, $content); return true; }
<?php require_once 'init.php'; $dbUnique = $_GET['u']; $dbConfig = getConfigByUnique($dbUnique); importClass('DB_Factory'); $dbFac = new DB_Factory($dbConfig); $bakDir = 'e:/0501/'; $dbRecover = $dbFac->getRecover($bakDir); $allBakTables = $dbRecover->getBakTables(); if ($_GET['tables']) { $recover = explode('|', $_GET['tables']); $dbRecover->recoverPartsTables($recover); exit('ok'); } //V($allBakTables); //$recover = array('user_report') ; //$dbRecover->recoverPartsTables($recover) ; //exit; //$result = $dbRecover->recoverAllFiles() ; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <base href="<?php echo URL; ?> " /> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $_HERO['charset']; ?>