phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


ADOdb: Update Data Style

Tag: adodb, database, database layer   Category: PHP Database
post: 31 Oct 2007 read: 759


ADOdb have function for updating data. If insert data using GetInsertSQL( ), for update data using GetUpdateSQL( ). Below a sample code.


<?php
include('adodb.inc.php'); 
    #========================== 
    # This code tests an insert 

    $sql = "SELECT * FROM ADOXYZ WHERE id = -1";  
    # Select an empty record from the database 

    $conn = &ADONewConnection("mysql"); 
# create a connection 
    $conn->debug=1; 
    $conn->PConnect("localhost", "admin", "", "test"); 
# connect to MySQL, testdb 
    #========================== 
    # This code tests an update 
    $sql = "SELECT * FROM ADOXYZ WHERE id = 1"; 

    # Select a record to update 
    $rs = $conn->Execute($sql); 
    # Execute the query and get 
    #the existing record to update 

    $record = array(); 
    # Initialize an array to hold 
    #the record data to update 

    # Set the values for the fields in the record 
    $record["firstname"] = "Caroline"; 
    $record["lastname"] = "Smith"; 
    # Update Caroline's lastname from Miranda to Smith 

    # Pass the single record recordset 
    # and the array containing the data to update 
    # into the GetUpdateSQL function. 
    # The function will process the data and return 
    # a fully formatted update sql statement 
    # with the correct WHERE clause. 
    # If the data has not changed, 
    # no recordset is returned 
    $updateSQL = $conn->GetUpdateSQL($rs, $record); 

    $conn->Execute($updateSQL); # Update the record in the database 
?>



| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting