method createTable documentation in bbn\Db\Languages\Mysql

function($table_name, array $columns, array $keys = NULL, bool $with_constraints = false, string $charset = 'utf8', string $engine = 'InnoDB') { $lines = []; $sql = ''; foreach ($columns as $n => $c) { $name = $c['name'] ?? $n; if (isset($c['type']) && bbn\Str::checkName($name)) { $st = $this->colSimpleName($name, true) . ' ' . $c['type']; if (!empty($c['maxlength'])) { $st .= '(' . $c['maxlength'] . ')'; } elseif (!empty($c['values']) && \is_array($c['values'])) { $st .= '('; foreach ($c['values'] as $i => $v) { $st .= "'" . bbn\Str::escapeSquotes($v) . "'"; if ($i < count($c['values']) - 1) { $st .= ','; } } $st .= ')'; } if ((strpos($c['type'], 'int') !== false) && empty($c['signed'])) { $st .= ' UNSIGNED'; } if (empty($c['null'])) { $st .= ' NOT NULL'; } if (array_key_exists('default', $c)) { $st .= ' DEFAULT ' . ($c['default'] === 'NULL' ? 'NULL' : "'" . bbn\Str::escapeSquotes($c['default']) . "'"); } $lines[] = $st; } } if (count($lines)) { $sql = 'CREATE TABLE ' . $this->tableSimpleName($table_name, true) . ' (' . PHP_EOL . implode(',' . PHP_EOL, $lines) . PHP_EOL . ') ENGINE=' . $engine . ' DEFAULT CHARSET=' . $charset . ';'; } return $sql; }

BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.