Home>

The code to create the SQL table structure in PHP was made below,
For example, is it possible to put the initial value ($X) in Textarea1?

$X ='Aiueo';

If i can,
I want you to tell me what kind of code it will be.

I couldn't find what I wanted to do by searching.
You may not be able to do it,
I look forward to working with you.

$sql = "CREATE TABLE hoge (CREATE TABLE hoge)
`Id` int (11) AUTO_INCREMENT PRIMARY KEY NOT NULL,
`Textarea1` varchar (400) NOT NULL,
`Textarea2` varchar (400) NOT NULL
) ENGINE = InnoDB DEFAULT CHARSET = utf8 ";
$pdo->query ($sql);
  • Answer # 1

    Is it possible to put the initial value ($X) in Textarea1?

    I'm not sure what I want to do,
    "Initial value when the value was not set at the time of INSERT"Can be set.
    As the name implies, CREATE TABLE only creates a table, and you can't "put a value in it without a row". Textarea2 is also set to not null.

    CREATE TABLE syntax

    column_definition:
    data_type [NOT NULL | NULL] [DEFAULT default_value]
    [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY]
    [COMMENT'string']
    [COLUMN_FORMAT {FIXED | DYNAMIC | DEFAULT}]
    [STORAGE {DISK | MEMORY | DEFAULT}]
    [reference_definition]

    Example:Textarea1 varchar (400) default'aiueo' NOT NULL,

    In any case, SQL is also executed one by one (although you can insert multiple lines with bulk insert).
    If you want to put a valueINSERT after CREATEneed to do it.

    However, I don't think there is a requirement to create TABLE from PHP in most cases.
    Every time I run that PHP, I try to make a table,IF NOT EXISTSSince it is not attached, an error will be returned from the second time onward.
    When using from PHP, it is often "created first and used".