Overview

Packages

  • objSQL

Documentation

  • objSQL Connection
  • objSQL Error Handling
  • General Queries
  • Prepared Statements
  • Transactions
  • Resultset Methods
  • Helper Method - Select Query
  • Helper Method - Update Query
  • Helper Method - Insert Query
  • Helper Method - Delete Query
  • Helper Method - Paging Query
  • Utility Methods

Classes

  • mysql_connection
  • mysql_prepare
  • mysql_resultset
  • mysql_statement
  • mysql_transaction
  • objSQL
  • pgsql_connection
  • pgsql_prepare
  • pgsql_resultset
  • pgsql_statement
  • pgsql_transaction
  • sqlite3_connection
  • sqlite3_prepare
  • sqlite3_resultset
  • sqlite3_statement
  • sqlite3_transaction
  • sqlsrv_connection
  • sqlsrv_prepare
  • sqlsrv_resultset
  • sqlsrv_statement
  • sqlsrv_transaction
  • Overview
  • Package
  • Class
  • Tree

objSQL Helper Method: Update

The obj_update() helper method executes an update statement with minimal SQL markup and is called from the objSQL class.

  • The $table argument is required.
  • The $data argument is required and MUST be a key value pair array with the table column as the key.
  • The optional $where argument allows you to limit which rows are updated and only requires the column and its value. You can use any of the normal operators used in SQL statements:
    • "location IN ('Athens','London')"
    • "location='Valdosta' AND dept='IT'"
    • "salary BETWEEN 20000 AND 40000"
  • obj_update() will update all records in a database table if used without a where clause and steps should be taken in any script or program to utilize a confirmation before executing this method unless the intention is to update the entire table.

Returns: Result resource/object or false on failure.

<?php

//usage: $dbh->obj_update( $table, $data, $where )

try
{
    
$data = array( "color" => "blue",
                   
"type"  => "leather",
                   
"price" => 36.95 );
    
    
$rs = $dbh->obj_update( "products", $data, "prod_id=21" );
    
    if ( 
$dbh->obj_error() )
        throw new 
Exception( $dbh->obj_error_message() );
        
    echo 
$rs->obj_affected_rows();
    
}
catch ( 
Exception $e ) 
{
    
//log error and/or redirect user to error page
} 

?>     

Downloads | Support | Contact

objSQL 3.0.1 API documentation generated by ApiGen 2.8.0

Documentation licensed under a Creative Commons Attribution 3.0 Unported License.