Version: v2.4.0
create
Create a new table.
create($table, $columns, $options)
table [string]
The name of the table to create.
columns [array]
The column definitions for the new table.
options [array/string] (optional)
Additional options to apply when creating the table.
Return Value
[PDOStatement] The PDOStatement instance for the executed query.
Basic Sample
Define each column as an array. Medoo will combine the parts into a complete column definition.
$database->create("account", [
"id" => [
"INT",
"NOT NULL",
"AUTO_INCREMENT",
"PRIMARY KEY"
],
"first_name" => [
"VARCHAR(30)",
"NOT NULL"
]
]);
CREATE TABLE IF NOT EXISTS account ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name VARCHAR(30) NOT NULL )
Advanced
You can also pass raw strings as column definitions for additional options. The
<column_name> syntax is supported as a shortcut for identifier quoting.$database->create("account", [
"id" => [
"INT",
"NOT NULL",
"AUTO_INCREMENT"
],
"email" => [
"VARCHAR(70)",
"NOT NULL",
"UNIQUE"
],
"PRIMARY KEY (<id>)"
], [
"ENGINE" => "MyISAM",
"AUTO_INCREMENT" => 200
]);
CREATE TABLE IF NOT EXISTS account ( id INT NOT NULL AUTO_INCREMENT, email VARCHAR(70) NOT NULL UNIQUE, PRIMARY KEY (`id`) ) ENGINE = MyISAM, AUTO_INCREMENT = 200