从mysql数据库读取数据表的信息,自动创建模型shell脚本

#################################
 # 从数据库读取数据表,                #
 # 并使用php think 命令批量创建模型    #
 #################################
########变量列表:##########
 #数据库名称         DB
 #thinkphp主目录     TPPATH
 #
 #
 ##########################
 DB=chenrui
 TPPATH=/var/www/html/tp5/
#  数据库需要用root权限
 #  读取数据库中的表,在/tmp/目录下生成tables.sql文件
 sudo mysql -h127.0.0.1 -uroot -proot -P3306 -Ne "use $DB;show tables;" > /tmp/tables.sql
#切换到tp5的目录,
 #注意:不切换目录的话,php think命令不能执行
 cd $TPPATH
#从文件中读取数据表的数据
 for TABLE in `cat /tmp/tables.sql `
do
     #由于数据表的数据,首字母是小写,所以要把转首字母转换成大写
     TABLE=${TABLE^}
    #执行创建模型操作
     #注意 以下是在index前台模块下创建模型,
     #     如果创建了其他模块,需要修改index为其它模块名
     php think make:model index/$TABLE &> /dev/null
     #判断结果
     if [ $? -eq 0 ]
     then
         echo "数据表:$TABLE模型 创建成功^_^"
     else
         echo "数据表:$TABLE模型 创建失败 cry ....,请单独手动操作"
     fi
done
以上是 从mysql数据库读取数据表的信息,自动创建模型shell脚本 的全部内容, 来源链接: utcz.com/z/532225.html

