Speed up development with full-stack environments for every branch.

Learn More

Open a database and get rows (both single and multiple) [sqlite3 and PHP]

98 Runs 707 Views 219 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<pre>
<?php
/*
 * PHP SQLite3 - Open a database and get rows (both single and multiple)
 */
//a file that creates and populates the table used in this example
require_once('createmyusers.php');

//Open the database mydb
$db = new SQLite3('mydb');

//Get multiple rows from myusers table 
echo "Get multiple rows from myusers table <br />";
$results = $db->query('SELECT username,password FROM myusers');
while ($row = $results->fetchArray()) {
    var_dump($row);
}

//Get single row from myusers table
echo "Get single row from myusers table <br />";
$admin = $db->querySingle('SELECT username,password FROM myusers WHERE username="admin"', true);
var_dump($admin);
?>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).