1. Go to this page and download the library: Download stepmuel/sjmsqlayer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
stepmuel / sjmsqlayer example snippets
// Open SQLite database
$db = new PDO('sqlite:db.sqlite');
// Create SJMSQLayer object
$dbl = new SJMSQLayer($db);
// Activate logging
$dbl->log = array();
// Use SJMSQLayer
$dbl->query("DROP TABLE %K", "books")->exec();
// Show all executed queries including error messages
print_r($dbl->log);
// Common examples
$dbl->query('INSERT INTO books %I', $data);
$dbl->query('UPDATE foo SET %S WHERE %W', $data, $where);
$dbl->query('SELECT name FROM books WHERE %W', $where);
$dbl->query('SELECT name FROM books WHERE id IN (%@)', $ids);
$dbl->query('DELETE FROM books WHERE %W', $where);
// Advanced usage
$where = array();
// numbers are not quoted
$where['year'] = 1605;
// strings are
$where['name'] = "Don Quixote";
// null handling
$where['deleted'] = null;
// arrays generate IN (v1, v2)
$where['id'] = array(1, 2, "string");
// insert statement by using integer key
$where []= "pages < 1000";
// generate SQL
echo $dbl->query('SELECT name FROM books WHERE %W', $where)->query;
class SJMSQLayerStatement {
public $sql = null;
public function exec();
public function get($key=false);
public function getAll($key=false);
public function getDict($dictKey, $valueKey=false);
public function getGroup($groupKey, $valueKey=false);
}
$stm = $dbl->query("SELECT * FROM books");
// get array of all book id's
$stm->getAll("id");
// get a dictionary of book titles by id
$stm->getDict("id", "title");
// get a dictionary of book id's by year
$stm->getDict("published", "id");
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.