insert Back | Forward | Home

'Language Reference'

User Functions

Database Functions

Data Manipulation Functions
  • select

  • insert

  • update

  • delete

  • execute


  • Table Functions

    Error Handling Functions

    << Last Section ( select ) insert Next Section ( update ) >>
    Usage void insert( array( 'table' => $table, 'values' => $values [, 'db' => $db] ) )
    Purpose To insert values into a txtSQL table
    Availability txtSQL >= 2.2.2 RC2

    This function will insert a row of data, containing the $values given, into an existing txtSQL database. The $values must be an array in the following format

         array([$column => $value]...)

    where $column is the name of the column that txtSQL will insert into, and $value is the value for that corressponding column. If the column does not exist, txtSQL will issue an error.

    If a column is of type auto_increment, txtSQL will automatically increment that column. If a column is of type enum and the value being inserted does not exist as one of the enum values, the last value from the enum list is inserted.

    Important- To achieve the same results as this function before txtSQL 2.2.2 RC2, use the execute() function
    Note- If the value does not match the data type (i.e. a string being inserted into an integer column), txtSQL will automatically format the value
    Note- If a column is set to permanent, you will not be able to change this value
    Note- If no $db is specified and no database is already selected, txtSQL will issue an error

    Example 16: insert() Copy to Clipboard
    <?php
    $values
    = array('id'       => 2,
                    
    'name'     => 'John',
                    
    'lastname' => 'Doe',
                    
    'Age'      => 22);

    if ( !
    $sql->insert(array('db'     => 'testDB',
                             
    'table'  => 'testTable',
                             
    'values' => $values)) )
    {
        die(
    'An error occurred, txtSQL said: '.$sql->get_last_error());
    }
    ?>

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