/**
     * 创建数据表SQL
     * @param $tableName
     * @return string
     */
    public  function createTable($tableName)
    {
        $result = DB::select("SHOW CREATE TABLE {$tableName}");
        $sql = $this->start_line;
        foreach ($result as $item){
            $item = object_to_array($item);
            $sql.="-- ----------------------------\n-- Table structure for {$item['Table']}\n-- ----------------------------\n";
            $sql.= "DROP TABLE IF EXISTS `".$item["Table"]."`;";
            $sql.= "\n".$item['Create Table'];
            $sql.=";\n".$this->str_line;  #自定义分割线
        }
        return $sql;
    }

    /**
     * 数据表数据SQL
     * @param $tableName
     * @return bool|string
     */
    public function sourceTable($tableName)
    {
        $result = DB::select("SELECT * FROM `".$tableName."`");
        $sql=";\n-- ----------------------------\n-- Records of $tableName\n-- ----------------------------\n";
        if (empty($result)){
            return $sql;
        }
        foreach ($result as $item){
            $sql.="INSERT INTO `".$tableName."` VALUES (";
            foreach ($item as $keys => $rows) {
                $sql.= "'$rows',";
            }
            $sql.=");";
            $sql= substr($sql,0,strlen($sql)-3); //删除最后三个字符串
            $sql.=");\n";
        }
        $sql.= $this->end_line;
        $sql=rtrim($sql, ',');
        return $sql;
    }

数据库备份操作

相关文章:

  • 2021-12-06
  • 2021-11-30
  • 2021-12-06
  • 2021-10-13
  • 2021-07-29
  • 2022-12-23
  • 2021-06-21
  • 2022-12-23
猜你喜欢
  • 2022-01-20
  • 2021-12-10
  • 2022-12-23
  • 2021-11-17
  • 2021-09-16
  • 2022-12-23
相关资源
相似解决方案