您好,欢迎访问一九零五行业门户网

YII2中,MODEL获取表字段作为属性的方式为什么是使用“SHOW FULL COLUMNS FROM TABLE”?

yii2中,model获取表字段作为属性的方式是使用“show full columns from table”,而不是直接写在model中。这样不时读数据库信息,这种额外开销感觉没必要,毕竟表结果不经常修改的。是基于什么原因使用这种方式呢?
protected function loadtableschema($name) { $table = new tableschema; $this->resolvetablenames($table, $name); if ($this->findcolumns($table)) { $this->findconstraints($table); return $table; } else { return null; } }

protected function findcolumns($table) { $sql = 'show full columns from ' . $this->quotetablename($table->fullname); try { $columns = $this->db->createcommand($sql)->queryall(); } ......... }

回复内容: yii2中,model获取表字段作为属性的方式是使用“show full columns from table”,而不是直接写在model中。这样不时读数据库信息,这种额外开销感觉没必要,毕竟表结果不经常修改的。是基于什么原因使用这种方式呢?
protected function loadtableschema($name) { $table = new tableschema; $this->resolvetablenames($table, $name); if ($this->findcolumns($table)) { $this->findconstraints($table); return $table; } else { return null; } }

protected function findcolumns($table) { $sql = 'show full columns from ' . $this->quotetablename($table->fullname); try { $columns = $this->db->createcommand($sql)->queryall(); } ......... }

其它类似信息

推荐信息