ADOdb: Insert data style



This tutorial about how to insert data using ADOdb style. For inserting, you can use GetInsertSQL() function. It's realy simple.

<?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 
    $rs = $conn->Execute($sql); 
# Execute the query and get the empty recordset 

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

    # Set the values for the fields in the record 
    $record["firstname"] = "Bob"; 
    $record["lastname"] = "Smith"; 
    $record["created"] = time();

    # Pass the empty recordset and 
    #the array containing the data to insert 
    # into the GetInsertSQL function. 
    #The function will process the data and return 
    # a fully formatted insert sql statement. 
    $insertSQL = $conn->GetInsertSQL($rs, $record); 

    $conn->Execute($insertSQL);
?>


Series this article:
ADOdb: Introduction
ADOdb: Connection Statement
ADOdb: Advance Select Statement
ADOdb: How to show tables
ADOdb: How to show fields
ADOdb: How to show databases
ADOdb: Caching of Recordset
ADOdb: Recordset to HTML
ADOdb: Multi Database Connection
ADOdb: Data Dictionary
ADOdb: Quick Export Data
ADOdb: Insert data style
ADOdb: Replace Data
ADOdb: Log Query
PHP ADOdb: Understanding Pivot Table For Reporting
PHP ADOdb: Creating Pivot Table
PHP ADOdb: Creating Query to Build Pivot Table


Tag: adodb, database, database layer Category: PHP Database Post : October 31st 2007 Read: 5,480 Bookmark and Share

blog comments powered by Disqus