SQLite and PHP Wez Furlong Marcus Boerger LinuxTag 2003 Karlsruhe.

Slides:



Advertisements
Similar presentations
Connecting to Databases. connecting to DB DB server typically a standalone application Server runs on localhost for smaller sites –i.e. Same machine as.
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Persistence 2: SQLite CS 344 Mobile App Development Robert Muller.
SQLLite and Java CS-328 Dick Steflik. SQLLite Embedded RDBMS ACID Compliant Size – about 257 Kbytes Not a client/server architecture –Accessed via function.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
WHAT IS PHP PHP is an HTML-embedded scripting language primarily used for dynamic Web applications.
Introducing PHP Data Objects Wez Furlong
SQLite Database. SQLite Public domain database – Advantages Small (about 150 KB) – Used on devices with limited resources Each database contained within.
Apache Chemistry face-to-face meeting April 2010.
Databases with PHP A quick introduction. Y’all know SQL and Databases  You put data in  You get data out  You can do processing on it very easily 
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Memcached HTTPd mcd DB HTTPd mcd [memcached 설치 및 구동 ] -- memory object caching system *) 설정 없음 1. 설치 - memcached or /usr/ports/databases/memcached.
PDO, PHP Data Object Use a Database with PHP
PHP Data Object (PDO) Khaled Al-Sham’aa. What is PDO? PDO is a PHP extension to formalise PHP's database connections by creating a uniform interface.
PHP Data Objects Layer (PDO) Ilia Alshanetsky. What is PDO Common interface to any number of database systems. Common interface to any number of database.
Sayed Ahmed Computer Engineering, BUET, Bangladesh MSC, Computer Science, U of Manitoba, Canada
MongoDB An introduction. What is MongoDB? The name Mongo is derived from Humongous To say that MongoDB can handle a humongous amount of data Document.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 19: Database Support.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Codeigniter is an open source web application. It occupies a very small amount of space in the memory and is most useful for developers who aim to develop.
Data File Access API : Under the Hood Simon Horwith CTO Etrilogy Ltd.
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
Chapter 6 PHP Interacts with Mysql Database. Introduction In PHP, there is no consolidated interface. Instead, a set of library functions are provided.
SQL 101 for Web Developers 14 November What is a database and why have one? Tables, relationships, normalization SQL – What SQL is and isn’t – CRUD:
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
Oracle SQL Query and Transactions By Shyam Gurram.
Lecture 10 – MYSQL and PHP (Part 2)
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
SQLite Supported by BlackBerry OS 5.0 Using SQLite.
PHP 5 Sucks! PHP 5 Rocks! Adam Trachtenberg eBay Technical Evangelist
PHP+MySQL Integration. Connecting to databases One of the most common tasks when working with dynamic webpages is connecting to a database which holds.
DBMS Implementation Chapter 6.4 V3.0 Napier University Dr Gordon Russell.
© Anselm Spoerri Web Design Information Visualization Course Prof. Anselm Spoerri
Working with PHP and Postgresql. pg_connect ( string $connection_string [, int $connect_type ] ) pg_connect() opens a connection to a PostgreSQL database.
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
Web-Based Database Programming with PHP. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn PHP Basics PHP functions –To.
Pengantar Teknologi Internet W14: Server Scripting & Database.
2010/11 : [1]PHP with MySQLBuilding Web Applications using MySQL and PHP (W1) PHP with MySQL.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Standalone Databases In the name of Allah Iman M.Gowhari
Web Programming Language Week 7 Dr. Ken Cosh PHP and storage.
© All rights reserved. U.S International Tech Support
Introduction to File Processing with PHP - Part 2 Indexed Files.
1 CS 430 Database Theory Winter 2005 Lecture 14: Additional SQL Topics.
PHP Data Objects Wez Furlong. About the author PHP Core Developer since 2001 Author of the Streams layer “King” of PECL Author of most of PDO and its.
PHP Workshop ‹#› PHP Data Object (PDO). PHP Workshop ‹#› What is PDO? PDO is a PHP extension to formalise PHP's database connections by creating a uniform.
Mobile Software Development ISCG 7424 Department of Computing UNITEC John Casey and Richard Rabeder SQLite and Permissions.
PHP Workshop ‹#› أطلق إبداعك 2 أطلق إبداعك 2 مدرس معتمد من مركز زووم PHP Data Object (PDO)
Connecting, Queries, Best Practices Tran Anh Tuan Edit from Telerik Software Academy
SQLite DB Storing Data in Android RAVI GAURAV PANDEY 1.
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
Unit-8 Introduction Of MySql. Types of table in PHP MySQL supports various of table types or storage engines to allow you to optimize your database. The.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
CHAPTER 9 File Storage Shared Preferences SQLite.
TerarkDB Introduction Peng Lei Terark Inc ( ). All rights reserved 1.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
Introduction to Database Programming with Python Gary Stewart
PHP Data Objects for MySQL
Introduction to PHP FdSc Module 109 Server side scripting and
PHP –MySQL Interview Question And Answer.
SQL – Application Persistence Design Patterns
Translation of ER-diagram into Relational Schema
ISC440: Web Programming 2 Server-side Scripting PHP 3
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Department of School of Computing and Engineering
SQLLite and Android.
SQL – Application Persistence Design Patterns
Presentation transcript:

SQLite and PHP Wez Furlong Marcus Boerger LinuxTag 2003 Karlsruhe

SQLite  Started in 2000 by D. Richard Hipp  Single file database  Subselects, Triggers, Transactions, Views  Very fast, 2-3 times faster than MySQL, PostgreSQL for many common operations  2TB data storage limit  Views are read-only  No foreign keys  Locks whole file for writing

PHP with SQLite  SQLite library integrated with PHP extension  PHP extension available via PECL for PHP 4.3  Bundled with PHP 5  API designed to be logical, easy to use  High performance  Convenient migration from other PHP database extensions  Call PHP code from within SQL

Dedicated Host Browser Internet Apache mod_php ext/sqlite SQL

ISP/Shared Host Browser Internet Apache mod_php ext/sqlite SQL

Embedded GTK / ??? CLI / EMBED ext/sqlite SQL

Opening and Closing resource sqlite_open(string filename [, int mode [, string & error_message ]])  Creates a non existing database file  Checks all security relevant INI options  Also has a persistent (popen) variant void sqlite_close(resource db)  Closes the database file and all file locks

<?php // Opening and Closing // Open the database (will create if not exists) $db = sqlite_open("foo.db"); // simple select $result = sqlite_query($db, "SELECT * from foo"); // grab each row as an array while ($row = sqlite_fetch_array($result)) { print_r($row); } // close the database sqlite_close($db); ?>

Query Functions resource sqlite_query ($db, $sql [, int result_type ])  Buffered query = Flexible  More memory usage  Also have an unbuffered variant = Fast array sqlite_array_query ($db, $sql [,int result_type]])  Flexible, Convenient  Slow with long result sets

<?php // Default result type SQLITE_BOTH $result = sqlite_query($db, "SELECT first, last from names"); $row = sqlite_fetch_array($result); print_r($row); ?> Array ( [0] => Joe [1] => Internet [first] => Joe [last] => Internet )

<?php // column names only $result = sqlite_query($db, "SELECT first, last from names"); $row = sqlite_fetch_array($result, SQLITE_ASSOC); print_r($row); ?> Array ( [first] => Joe [last] => Internet )

<?php // column numbers only $result = sqlite_query($db, "SELECT first, last from names"); $row = sqlite_fetch_array($result, SQLITE_NUM); print_r($row); ?> Array ( [0] => Joe [1] => Internet )

assign("names", $rows); ?>

assign("names", $rows); ?>

Array Interface array sqlite_fetch_array (resource result [, int result_type [, bool decode_binary ]])  Flexible  Slow for large result sets array sqlite_fetch_all (resource result [, int result_type [, bool decode_binary ]])  Flexible  Slow for large result sets; better use sqlite_array_query ()

Single Column Interface mixed sqlite_single_query ($db,$sql [, bool first_row_only])  Fast  Only returns the first column string sqlite_fetch_single ($result)  Fast  Slower than sqlite_single_query mixed sqlite_fetch_single ($result, $index_or_name)  Flexible, Faster than array functions  Slower than other single functions

<?php $count = sqlite_single_query($db, "SELECT count(first) from names"); echo “There are $count names"; ?> There are 3 names

<?php $first_names = sqlite_single_query($db, "SELECT first from names"); print_r($first_names); ?> Array ( [0] => Joe [1] => Peter [2] => Fred )

Meta information int sqlite_num_rows (resource result)  Number of rows in a SELECT int sqlite_num_fields (resource result)  Number of columns in a SELECT int sqlite_field_name (resource result, int field_index)  Name of a selected field int sqlite_changes (resource db)  Number of rows changed by a UPDATE/REPLACE int sqlite_last_insert_rowid (resource db)  ID of last inserted row

Iterator Interface array sqlite_current (resource result [, int result_type [, bool decode_binary ]])  Returns the current selected row bool sqlite_rewind (resource result)  Rewind to the first row of a buffered query bool sqlite_next (resource result)  Moves to next row bool sqlite_has_more (resource result)  Returns true if there are more rows bool sqlite_seek (resource result, int row)  Seeks to a specific row of a buffered query

Using Iterators <?php $db = sqlite_open("…"); for ($res = sqlite_query ("SELECT…", $db); sqlite_has_more ($res); sqlite_next ($res)) { print_r (sqlite_current ($res)); } ?>

Calling PHP from SQL bool sqlite_create_function (resource db, string funcname, mixed callback [, long num_args ])  Registers a "regular" function bool sqlite_create_aggregate (resource db, string funcname, mixed step, mixed finalize [, long num_args ])  Registers an aggregate function

<?php function md5_and_reverse($string) { return strrev(md5($string)); } sqlite_create_function($db, 'md5rev', 'md5_and_reverse'); $rows = sqlite_array_query($db, 'SELECT md5rev(filename) from files'); ?>

$context) { $context = strlen($string); } } function max_len_finalize(&$context) { return $context; } sqlite_create_aggregate($db, 'max_len', 'max_len_step', 'max_len_finalize'); $rows = sqlite_array_query($db, 'SELECT max_len(a) from strings'); print_r($rows); ?>

Handling binary data in UDF string sqlite_udf_encode_binary (string data)  Apply binary encoding (if required) to a string to be returned from an UDF string sqlite_udf_decode_binary (string data)  Decode binary encoding on a string parameter passed to an UDF

Handling Binary Data string sqlite_escape_string (string data)  Escapes quotes appropriately for SQLite  Applies a safe binary encoding for use in SQLite queries  Values must be read with the decode_binary flag turned on (default!)

Utility Functions void sqlite_busy_timeout (resource db, int ms)  Set busy retry duration.  If ms <= 0, no waiting if performed int sqlite_last_error (resource db)  Returns last error code from database string sqlite_error_string (int error_code)  Converts error code to a readable string string sqlite_libversion ()  Returns version of the linked SQLite library string sqlite_libencoding ()  Returns charset encoding used by SQLite library

Resources  Documentation at