Simplified Database Connectivity


<cfinsert> and <cfupdate> are tags that simplify the process of database inserts and updates, respectively. They effectively build a dynamic SQL statement based on the FORM variable structure and submit it like a standard <cfquery> with the appropriate SQL statement. Consequently, they are easier to use than <cfquery> and SQL code, but they are also less flexible and have some limitations. Only datasource and tablename are required attributes. <cfinsert> and <cfupdate> are used like this:

 <!--- inserting a record ---> <cfinsert datasource="dsn"           tablename="users"           formfields="LastName, FirstName"> <!--- updating a record ---> <cfupdate datasource="dsn"           tablename="users"           formfields="LastName, FirstName"> 

<cfinsert> and <cfupdate> have the following restrictions:

  • They can submit only FORM variables.

  • The form field names must be the same as the corresponding column names in the database table.

  • <cfupdate> must include values for all the columns that make up the table's primary key.

The formfields attribute acts as a mask, allowing only specified form fields to be included in the operation. If formfields is not present, all the form fields are submitted. Other tag attributes are available to override default settings in the data source connection.

TIP

<cfparam> can be used to create default form fields for use with <cfinsert> and <cfupdate>.




Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net