PHP
  Home arrow PHP arrow Page 3 - Additional Methods for Using SQLite wi...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Additional Methods for Using SQLite with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2006-12-18

    Table of Contents:
  • Additional Methods for Using SQLite with PHP 5
  • Using the seek() and lastInsertRowid() methods
  • Using the changes() and queryExec() methods
  • Using the createFunction() method
  • Creating databases in server memory

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Additional Methods for Using SQLite with PHP 5 - Using the changes() and queryExec() methods


    (Page 3 of 5 )

    As I mentioned at the end of the previous section, I’m going to show you a couple of additional methods bundled with the SQLite library that can be valuable. They work well for those situations where you want to use an alternative way to run queries, and for determining the number of rows affected after performing a DML statement.

    The first method that I’ll teach you is “queryExec().” It consists of a simple replacement of the “query()” method that you learned before. Here’s how to use it:

    // example using the 'queryExec()' method

    // create new database using the OOP approximation

    $db=new SQLiteDatabase("db.sqlite");

    $query="INSERT INTO users (id,name,email) VALUES(NULL,'John
    Doe','john@domain.com')";

    if(!$db->queryExec($query)){

                trigger_error('Error performing
    query'.$query,E_USER_ERROR);

    }

    If you take some time and examine the above short example, you’ll understand why I said the “queryExec()” method can be used as an alternative to the previously reviewed “query().” In this case, the example speaks for itself, therefore I suggest you pay attention to the following code sample. It is much more useful, since it illustrates a basic application of the brand new “changes()” method.

    The script listed below shows precisely how you can use this method to calculate the number of affected row after running a DML statement:

    // example using the 'changes()' method

    // create new database using the OOP approximation

    $db=new SQLiteDatabase("db.sqlite");

    // insert new row into 'USERS' database table

    $db->query("INSERT INTO users (id,name,email) VALUES
    (NULL,'User4','user1@domain.com')");

    echo 'Number of rows modified after the insertion '.$db->changes();

    /*

    // displays the following

    Number of rows modified after the insertion 1

    As you can see in the above example, the “changes()” method can be really helpful if you want to know how many rows were affected after inserting, updating or deleting records of a particular database. Of course, this method is closely similar to the PHP “mysql_affected_rows()” function, therefore you shouldn’t have too many problems understanding how it works.

    All right, at this stage I believe that you’ve been provided with a neat set of SQLite methods which can be used for tackling different tasks. However, we’ve not come to the end of the tutorial yet, since there are a few more methods that remain uncovered.

    Speaking of that, in the following section, I’ll teach you how to use iterators to traverse different result sets, and how to define custom functions with SQLite as well. Therefore, jump straight into the next lines and keep reading.

    More PHP Articles
    More By Alejandro Gervasio


       · Over the course of this final installment of the series, you'll see how to perform...
     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT