获取表结构,必须是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