zoukankan      html  css  js  c++  java
  • 生成数据库模型文件

    //生成数据库模型;
     

    $con = mysqli_connect("{host}","{user}","{pass}","(database)",“{port}”);
    if(!$con){
    die('database connect error!');
    }
    $sqlTableModel = [];
    $result = mysqli_query($con,"SHOW TABLES");

    while($row = mysqli_fetch_array($result))
    {
    $sqlTableModel[]= table_str_func($row[0]);
    }
    //dump($sqlTableModel);die;
    return [
    // 生成应用公共文件
    '__file__' => ['common.php', 'config.php', 'database.php'],
    //生成数据库模型
    'common' => [
    '__dir__' => ['behavior','model','logic','service'],
    'model' => array_merge(["Base"],$sqlTableModel),
    'logic' => array_merge(["Base"],$sqlTableModel),
    'service' => array_merge(["Base"],$sqlTableModel),
    ],
    ]
     
    /**
    * 接受数据库表名称,去除前缀并转换为首字母大写,必须规范"x_y_z"
    * @param $str
    * @return string
    */
    function table_str_func($str)
    {
    $reg = '/^[a-zA-Z0-9]+_/';
    $t = preg_replace ($reg, "" , $str);
    $new_t = explode("_",$t);$new_str='';
    foreach ($new_t as $keies){
    $new_str .= ucfirst($keies);
    }
    return $new_str;
    }
     
    执行:php think build 
     
    成功生成!
    image
  • 相关阅读:
    回流与重绘
    事件循环的一些小啰嗦
    async与await的那些事儿
    数组去重的方法们
    Object的一些常用方法
    JS事件流的一些理解
    关于Ajax的那些记录
    call、bind与apply函数的区别
    继承的一些细碎记载
    计算机基础的小贴士(1)
  • 原文地址:https://www.cnblogs.com/q1104460935/p/6913124.html
Copyright © 2011-2022 走看看