Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created October 10, 2014 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/e5b098f976ee2238a42e to your computer and use it in GitHub Desktop.
Save phpfiddle/e5b098f976ee2238a42e to your computer and use it in GitHub Desktop.
[ Posted by Tejram ] pdo sqlite database
<?php
/**
* PDO SQLite initial code
*
* Using phpLiteAdmin to admin SQLite3 and SQLite2 database : inclibs/util/sqlite3.db, inclibs/util/sqlite2.db
*
* @package PhpFiddle
* @link http://phpfiddle.org
* @since 2012
*/
require_once "dBug!.php";
// for SQLite3 database
$dsn = "sqlite:inclibs/util/sqlite3.db";
$connect = new PDO($dsn);
//get all tables and column information in the database
$sql = "SELECT * FROM sqlite_master WHERE type = 'table'";
//SQL statement for a table data
//$sql = "SELECT * FROM Products WHERE ProductID <= 10";
$result = $connect->prepare($sql);
//bind parameter(s) to variable(s)
//$result->bindParam( . . . );
$result->execute();
$rows = $result->fetch();
//for one-time query, this line is same with code from line 19 to 24
//$result = $connect->query($sql);
$results = array();
//convert query result into an associative array
foreach($rows as $row)
{
$results[] = $row;
}
//dump all data from associative array converted from query result
new dBug($results);
$connect = null;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment