In YII2, the way for MODEL to obtain table fields as attributes is to use "SHOW FULL COLUMNS FROM TABLE" instead of writing them directly in MODEL. This extra overhead of reading database information from time to time seems unnecessary, after all, the table results are not modified frequently. What is the reason for using this method?
<code> protected function loadTableSchema($name) { $table = new TableSchema; $this->resolveTableNames($table, $name); if ($this->findColumns($table)) { $this->findConstraints($table); return $table; } else { return null; } }</code>
<code> protected function findColumns($table) { $sql = 'SHOW FULL COLUMNS FROM ' . $this->quoteTableName($table->fullName); try { $columns = $this->db->createCommand($sql)->queryAll(); } ......... }</code>
In YII2, the way for MODEL to obtain table fields as attributes is to use "SHOW FULL COLUMNS FROM TABLE" instead of writing them directly in MODEL. This extra overhead of reading database information from time to time seems unnecessary, after all, the table results are not modified frequently. What is the reason for using this method?
<code> protected function loadTableSchema($name) { $table = new TableSchema; $this->resolveTableNames($table, $name); if ($this->findColumns($table)) { $this->findConstraints($table); return $table; } else { return null; } }</code>
<code> protected function findColumns($table) { $sql = 'SHOW FULL COLUMNS FROM ' . $this->quoteTableName($table->fullName); try { $columns = $this->db->createCommand($sql)->queryAll(); } ......... }</code>