Also, the constructor takes the place of the sqlite_open() function,
negating the need to specifically open a database connection. The class is instantiated by calling the
constructor like so:
CHAPTER 22 ?– SQLITE 573
$sqldb = new SQLiteDatabase(string databasename [, int mode
[, string &error_message]]);
Once the object is created, you can call methods just as you do for any other class. For example,
you can execute a query and determine the number of rows returned with the following code:
$sqldb = new SQLiteDatabase("corporate.db");
$sqldb->query("SELECT * FROM employees");
echo $sqldb->numRows()." rows returned.";
See the PHP manual (http://www.php.net/sqlite) for a complete listing of the
available methods.
Creating a Table in Memory
Sometimes your application may require database access performance surpassing
even that offered by SQLite??™s default behavior, which is to manage databases in selfcontained
files. To satisfy such requirements, SQLite supports the creation of in-memory
(RAM-based) databases, accomplished by calling sqlite_open() like so:
$sqldb = sqlite_open(":memory:");
Once open, you can create a table that will reside in memory by calling sqlite_
query(), passing in a CREATE TABLE statement. Keep in mind that such tables are volatile,
disappearing once the script has finished executing.
Closing a Connection
Good programming practice dictates that you close pointers to resources once you??™re
finished with them.
Pages:
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658