createtable Back | Forward | Home

'Language Reference'

User Functions

Database Functions

Data Manipulation Functions

Table Functions
  • showtables

  • createtable

  • droptable

  • altertable

  • describe

  • table_count

  • empty_cache

  • table_exists

  • last_insert_id


  • Error Handling Functions

    << Last Section ( showtables ) createtable Next Section ( droptable ) >>
    Usage void createtable ( array ('table' => $tablename, 'columns' => $columns [, 'db' => $db]) )
    Purpose To create a txtSQL table inside a database
    Availability txtSQL >= 2.2.2 RC2

    This function will create a txtSQL table with the name $tablename, as long as it does not already exist. The columns that will be in this table will be defined in $columns part of the array. $columns must be an array in the following format

         array([$columnName => array([$coltype => $value]...)]... )

    For more information on on column types, see the column types section

    Important- To achieve the same results as this function before txtSQL 2.2.2 RC2, use the execute() function
    Note- If $tablename already exists, txtSQL will issue an error
    Note- If no $db is specified and no database is already selected, txtSQL will issue an error

    Example 21: createtable() Copy to Clipboard
    <?php
    $columns
    = array('id'    => array('type' => 'int', 'auto_increment' => 1, 'permanent' => 1
                     
    'name'  => array('type' => 'string', 'max' => 50),
                     
    'email' => array('type' => 'string', 'max' => 50)
                     );

    $sql->createtable('db'      => 'testDb',
                      
    'table'   => 'testTable',
                      
    'columns' => $columns);
    ?>

    User-Contributed Comments for:
    createtable()
    No comments found;