Created
October 10, 2014 17:36
-
-
Save phpfiddle/e5b098f976ee2238a42e to your computer and use it in GitHub Desktop.
[ Posted by Tejram ] pdo sqlite database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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