ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

PHP数据库批量去注释、删字段

2021-09-17 08:35:58  阅读:76  来源: 互联网

标签:Name COLUMN 数据库 value pdo ivalue 删字 PHP NAME


<?php

$host = "localhost";
$username = 'root';
$password = 'root';
$database = 'dbname';

$filters = ['content','payload'];

$pdo = new PDO("mysql:host={$host};dbname={$database}", $username, $password, array(PDO::ATTR_PERSISTENT => true));
$pdo->exec("set names 'utf8'");

$info = $pdo->query('SHOW TABLE STATUS;')->fetchAll(PDO::FETCH_ASSOC);

foreach ($info as $key => $value) {
// 删除所有表注释 $pdo->exec("ALTER TABLE " . $value['Name'] . " COMMENT '';");
$info = $pdo->query("select * from information_schema.columns where table_name = '" . $value['Name'] . "'")->fetchAll(PDO::FETCH_ASSOC); foreach ($info as $i => $ivalue) {
        // 删除整个数据库所有表中,存在在$filters数组中的列 if (in_array($ivalue['COLUMN_NAME'], $filters)) { $pdo->exec("ALTER TABLE " . $value['Name'] . " DROP COLUMN " . $ivalue['COLUMN_NAME'] . ";"); echo "删除表" . $value['Name'] . "中的:" . $ivalue['COLUMN_NAME']; echo " "; }
// 删除所有表的所有字段的注释 $pdo->exec("ALTER TABLE " . $value['Name'] . " MODIFY COLUMN " . $ivalue['COLUMN_NAME'] . " " . $ivalue['COLUMN_TYPE'] . " COMMENT '';"); echo "删除表" . $value['Name'] . "中的:" . $ivalue['COLUMN_NAME'] . "字段的注释"; echo " "; } }

 

 

标签:Name,COLUMN,数据库,value,pdo,ivalue,删字,PHP,NAME
来源: https://www.cnblogs.com/dwj192/p/15303050.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有