yii\db\Connection::getTableSchema PHP Method

getTableSchema() public method

Obtains the schema information for the named table.
public getTableSchema ( string $name, boolean $refresh = false ) : yii\db\TableSchema
$name string table name.
$refresh boolean whether to reload the table schema even if it is found in the cache.
return yii\db\TableSchema table schema information. Null if the named table does not exist.
    public function getTableSchema($name, $refresh = false)
    {
        return $this->getSchema()->getTableSchema($name, $refresh);
    }

Usage Example

Example #1
0
 /**
  * Create table if not exists
  */
 protected function createTable()
 {
     if ($this->db->getTableSchema($this->tableName) === null) {
         $this->db->createCommand()->createTable($this->tableName, ['id' => 'pk', 'created_at' => 'integer', 'updated_at' => 'integer', 'data' => 'binary'])->execute();
         $this->db->getTableSchema($this->tableName, true);
     }
 }
All Usage Examples Of yii\db\Connection::getTableSchema