Home    Back    Forward    Refresh    txtSQL Homepage

update
Purpose: To update rows with new values in a txtSQL table
txtSQL >= 2.2.2 RC2
int update ( array( 'table' => $table, $where => $where, 'values' => $values [, 'limit' => $limit [, 'db' => $db]] ) )

This function will update a row that matches the $where clause with the new information given in the $values, and returns the number of rows updated. 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 $limit is defined, then txtSQL will stop updating rows and return the number of rows updated at the $limit. NOTE- This limit only needs one value (i.e. array(20) stops at 21 rows) unlike a regular limit clause.

If a column is of type enum and the value being updated 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- For more information on defining a where clause, see the how to create a where clause section
Note- If the value does not match the data type (i.e. a string being updated in 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 17: update() Copy to clipboard
<?php
$values
= array('totalposts' => 244,
                
'email'      => 'John@doe.com');

if ( !
$sql->update(array('db'     => 'testDB',
                         
'table'  => 'testTable',
                         
'where'  => array('strtolower(name) = john doe'),
                         
'values' => $values,
                         
'limit'  => array(0))) )
{
    die(
'An error occurred, txtSQL said: '.$sql->get_last_error());
}
?>


User Comments - update
No comments posted yet;
Last Page Next Page

'Language Reference'

User Functions

Database Functions

Data Manipulation Functions
  • select
  • insert
  • update
  • delete
  • execute

    Table Functions

    Error Handling Functions

    SQL Syntax

  • [ txtSQL Documentation powered by txtSQL | 6 SQL Queries ]