thinkPHP5.0表结构读取和缓存

目录结构
生成数据表字段缓存

获取表结构,必须是MySQL中的完整表名
助手函数写法

$fields = db()->getConnection()->getFields($prefix . $module);

命名空间写法

$fields = Db::getFields($prefix . $module);

运行结果

array(8) {
  ["id"] => array(6) {
    ["name"] => string(2) "id"
    ["type"] => string(7) "int(10)"
    ["notnull"] => bool(false)
    ["default"] => NULL
    ["primary"] => bool(true)
    ["autoinc"] => bool(true)
  }
  ["admin_id"] => array(6) {
    ["name"] => string(8) "admin_id"
    ["type"] => string(7) "int(10)"
    ["notnull"] => bool(false)
    ["default"] => string(1) "0"
    ["primary"] => bool(false)
    ["autoinc"] => bool(false)
  }
  ["listorder"] => array(6) {
    ["name"] => string(9) "listorder"
    ["type"] => string(6) "int(4)"
    ["notnull"] => bool(false)
    ["default"] => string(1) "0"
    ["primary"] => bool(false)
    ["autoinc"] => bool(false)
  }
  ["status"] => array(6) {
    ["name"] => string(6) "status"
    ["type"] => string(10) "tinyint(2)"
    ["notnull"] => bool(false)
    ["default"] => string(1) "0"
    ["primary"] => bool(false)
    ["autoinc"] => bool(false)
  }
  ["create_time"] => array(6) {
    ["name"] => string(11) "create_time"
    ["type"] => string(7) "int(10)"
    ["notnull"] => bool(false)
    ["default"] => string(1) "0"
    ["primary"] => bool(false)
    ["autoinc"] => bool(false)
  }
  ["update_time"] => array(6) {
    ["name"] => string(11) "update_time"
    ["type"] => string(7) "int(10)"
    ["notnull"] => bool(false)
    ["default"] => string(1) "0"
    ["primary"] => bool(false)
    ["autoinc"] => bool(false)
  }
  ["delete_time"] => array(6) {
    ["name"] => string(11) "delete_time"
    ["type"] => string(7) "int(10)"
    ["notnull"] => bool(false)
    ["default"] => string(1) "0"
    ["primary"] => bool(false)
    ["autoinc"] => bool(false)
  }
  ["imgs"] => array(6) {
    ["name"] => string(4) "imgs"
    ["type"] => string(12) "varchar(250)"
    ["notnull"] => bool(false)
    ["default"] => string(0) ""
    ["primary"] => bool(false)
    ["autoinc"] => bool(false)
  }
}

字段缓存
版本要求V5.0.1
运行目录
在这里插入图片描述
执行后会自动在runtime/schema目录下面按照数据表生成字段缓存文件
所有表字段缓存

php think optimize:schema

指定数据库

php think optimize:schema --db demo

指定不同的数据库连接

php think optimize:schema --module index

指定数据表

php think optimize:schema --table think_user
php think optimize:schema --table demo.think_user
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值