| Start |
|---|
Querying a database See also http://stackoverflow.com/documentation/sql/topics (opens new window) |
| Retrieving only one result In addition to using LIMIT SQL statements you can also use the SQLite3 function |
| SQLite3 Quickstart Tutorial This is a complete example of all the commonly used SQLite related APIs. The aim is to get you up and running really fast. You can also get a runnable PHP file (opens new window) of of this tutorial. Creating/opening a databaseLet's create a new database first. Create it only if the file doesn't exist and open it for reading/writing.
The extension of the file is up to you, but Creating a tableInserting sample data.It's advisable to wrap related queries in a transaction (with keywords Insert potentially unsafe data with a prepared statement. You can do this with named parameters: Fetching dataLet's fetch today's visits of user #42. We'll use a prepared statement again, but with numbered parameters this time, which are more concise: Note: If there are no more rows, fetchArray() returns Free the memory - this in not done automatically, while your script is running ShorthandsHere's a useful shorthand for fetching a single row as an associative array. The second parameter means we want all the selected columns. Watch out, this shorthand doesn't support parameter binding, but you can escape the strings instead. Always put the values in SINGLE quotes! Double quotes are used for table and column names (similar to backticks in MySQL). Another useful shorthand for retrieving just one value. Cleaning upFinally, close the database. This is done automatically when the script finishes, though. |
Read Article
https://develop.horje.com/learn/1434/reference