yii2获取表及字段

来源:互联网 发布:我的世界一键生成js 编辑:程序博客网 时间:2024/05/18 03:23
<?phpnamespace frontend\controllers;use yii\web\Controller;use yii\db\Migration;use yii\db\Schema;class TableController extends Controller{    public function actionIndex()    {        $mir = new Migration();          $sch = new \yii\db\mysql\Schema;          $tableName='shang';        $db=Yii::$app->getDb();        $table=$db->createCommand("SHOW TABLES LIKE '".$tableName."'")->queryAll();        if($table==null)        {            echo '1';        }else{            echo '2';        }        // $mir->createTable('shang', [          //     'id' => 'pk',          //     'title' => $sch::TYPE_STRING . ' NOT NULL',          //     'content' => $sch::TYPE_TEXT,          // ]);          $r=$db->getSchema()->getTableNames();//获取表名        $r=$db->getSchema()->getTableSchema('shang');//获取表字段名    }    }
0 0
原创粉丝点击