| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- /**
- * 洛阳赤炎鹰网络科技有限公司
- * https://www.cyyvip.com
- * Copyright (c) 2022 赤店商城 All rights reserved.
- */
- /* *
- * 公共模型
- */
- namespace Common\Model;
- use Think\Model;
- class CommonModel extends Model {
- /**
- * 删除表
- */
- final public function drop_table($tablename) {
- $tablename = C("DB_PREFIX") . $tablename;
- return $this->query("DROP TABLE $tablename");
- }
- /**
- * 读取全部表名
- */
- final public function list_tables() {
- $tables = array();
- $data = $this->query("SHOW TABLES");
- foreach ($data as $k => $v) {
- $tables[] = $v['tables_in_' . strtolower(C("DB_NAME"))];
- }
- return $tables;
- }
- /**
- * 检查表是否存在
- * $table 不带表前缀
- */
- final public function table_exists($table) {
- $tables = $this->list_tables();
- return in_array(C("DB_PREFIX") . $table, $tables) ? true : false;
- }
- /**
- * 获取表字段
- * $table 不带表前缀
- */
- final public function get_fields($table) {
- $fields = array();
- $table = C("DB_PREFIX") . $table;
- $data = $this->query("SHOW COLUMNS FROM $table");
- foreach ($data as $v) {
- $fields[$v['Field']] = $v['Type'];
- }
- return $fields;
- }
- /**
- * 检查字段是否存在
- * $table 不带表前缀
- */
- final public function field_exists($table, $field) {
- $fields = $this->get_fields($table);
- return array_key_exists($field, $fields);
- }
-
- protected function _before_write(&$data) {
-
- }
- }
|