PHP框架项目中生成表结构
简介有时候想看表结构,并导出出来,需要借助其他工具,本文主要记录如何通过安装一个扩展直接将表结构导出成html的文件,可以随便发给其他人查看。
github地址:https://github.com/sclzzhanghaijun/db_schema
db_schema
本项目主要是生成Mysql的表结构,返回Html,可以自定义显示table样式。支持所有php项目,只需要实现数据查询方法。
安装
composer require sclzzhanghaijun/db_schema
Laravel使用
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use SCLZZHJ\Schema\Schema;
use SCLZZHJ\Schema\SchemaInterFace;
//实现接口
class DBSchema implements SchemaInterFace
{
public function SqlExec($sql)
{
$result = DB::select($sql);
if($result){
$result = $this->object_array($result);
}
return $result;
}
//需要将对象转换为数组
public function object_array($array) {
if(is_object($array)) {
$array = (array)$array;
} if(is_array($array)) {
foreach($array as $key=>$value) {
$array[$key] = $this->object_array($value);
}
}
return $array;
}
}
//使用命令方式调用
class SchemaCommand extends Command
{
protected $signature = 'make:table_schema';
protected $description = '生成数据表结构';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$schema = new Schema(new DBSchema(), config('database.connections.mysql.database'));
try {
$table = $schema->make();
$html = <<<EOF
<html lang="zh">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style ="text/css">
/*table start*/
table{
/* -moz-border-radius: 5px;
-webkit-border-radius:5px;
border-radius:5px; */
margin: auto;
width: 50%;
border:solid #333;
border-width:1px 0px 0px 1px;
font-size: #333;
border-collapse: collapse;
border-spacing: 0;
font-size: 13px;
}
table tbody tr{
height: 20px;
line-height: 20px;
}
table tbody tr.odd{
background-color: #fff;
}
table tbody tr.even{
background-color: #F5F5F5;
}
table tbody tr:hover{
background-color: #eee;
}
table tbody tr th,table tbody tr td{
padding:3px 5px;
text-align: left;
/* border: 1px solid #ddd; */
border:solid #333;
border-width:0px 1px 1px 0px;
}
table tbody tr th{
font-weight: bold;
text-align: center;
}
table tbody tr td a:hover{
color:#0080c0;
}
/*table end*/
</style>
EOF;
$html .= "<body>" . $table . "</body></html>";
file_put_contents("./index.html", $html);
} catch (\Exception $exception) {
echo $exception->getMessage();
}
}
}
最终效果


最近在做Golang的web框架日志,想将一个请求的所有日志上都绑定一个请求ID,由于最初框架的搭建没有解耦好,所以很难在日志中输出请求ID。于是想到了能否用协程ID来记录一个对应的请求ID,然后进行获取。
为了能让虚拟机能连接网络,并且能与宿主机能相互进行访问,所以需要多虚拟机几种网络模式进行学习,以便后期能快速的进行配置。
通常情况下,扩展一个类的功能会使用继承方式来实现。但继承具有静态特征,耦合度高,并且随着扩展功能的增多,子类会很膨胀。如果使用组合关系来创建一个包装对象(即装饰对象)来包裹真实对象,并在保持真实对象的类结构不变的前提下,为其提供额外的功能,这就是装饰模式的目标。
php中的array_walk_recursive函数对数组中的每个成员递归地应用用户函数
Composer 是 PHP 的一个依赖管理工具。我们可以在项目中声明所依赖的外部工具库,Composer 会帮你安装这些依赖的库文件,有了它,我们就可以很轻松的使用一个命令将其他人的优秀代码引用到我们的项目中来。
快速生成表格
Electron页面跳转、浏览器打开链接和打开新窗口
在使用Git的过程中,不想每次都输入用户名和密码去拉取代码,所以就需要保存这些信息,那么既然有保存了,就必须有清除功能。
在Mac电脑中,如何对Git的用户名和密码进行修改呢?起初不懂Mac,所以整了很久,本文将记录如何对这个进行操作,以便后期使用。
Docker编译镜像出现:fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.2c4ac24e.tar.gz: No such file or directory问题