1. Go to this page and download the library: Download simplon/db 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/ */
simplon / db example snippets
// connect to server "localhost", db "test" with user/pass "rootuser/rootuser"
$dbInstance = Mysql::Instance('localhost', 'test', 'rootuser', 'rootuser');
// connect to server "localhost", db "test" with user/pass "rootuser/rootuser"
$dbInstance = \Simplon\Db\DbInstance::MySQL('localhost', 'test', 'rootuser', 'rootuser');
// connect to server "localhost", db "test" with user/pass "rootuser/rootuser"
$dbInstance = \Simplon\Db\DbInstance::MySQL('localhost', 'test', 'rootuser', 'rootuser');
// ##############################################
// query
$results = $dbInstance->FetchAll('SELECT * FROM foobar WHERE ekey = :key', ['key' => 'BB']);
// dumps assoc. array of FALSE when fails
var_dump($results);
// connect to server "localhost", db "test" with user/pass "rootuser/rootuser"
$dbInstance = \Simplon\Db\DbInstance::MySQL('localhost', 'test', 'rootuser', 'rootuser');
// ##############################################
// create SqlManager instance
$sqlManager = new \Simplon\Db\SqlManager($dbInstance);
// query builder
$sqlQuery = (new \Simplon\Db\SqlQueryBuilder())
->setQuery('SELECT * FROM foobar WHERE ekey = :key')
->setConditions(['key' => 'BB']);
// query
$results = $sqlManager->fetchAll($sqlQuery);
// dumps assoc. array of FALSE when fails
var_dump($results);
// connect to server "localhost", db "test" with user/pass "rootuser/rootuser"
$dbInstance = \Simplon\Db\DbInstance::MySQL('localhost', 'test', 'rootuser', 'rootuser');
// ##############################################
// query: inserts one new row
$data = ['id' => NULL, 'ekey' => 'DD'];
$dbInstance->ExecuteSQL('INSERT INTO foobar VALUES (:id, :ekey)', $data);
// ##############################################
// query update
$data = ['id' => 5, 'ekey' => 'FF'];
$dbInstance->ExecuteSQL('UPDATE INTO foobar VALUES (:ekey) WHERE id = :id', $data);
// connect to server "localhost", db "test" with user/pass "rootuser/rootuser"
$dbInstance = \Simplon\Db\DbInstance::MySQL('localhost', 'test', 'rootuser', 'rootuser');
// ##############################################
// query: inserts one new row
$data = ['id' => NULL, 'ekey' => 'DD'];
$sqlQuery = (new SqlQueryBuilder())
->setTableName('foobar') // define the table name
->setData($data); // set data (keys = database column name)
$sqlManager->insert($sqlQuery);
// ##############################################
// query update
$conds = ['id' => 5];
$data = ['ekey' => 'FF'];
$sqlQuery = (new SqlQueryBuilder())
->setTableName('foobar') // define the table name
->setConditions($conds) // set conditions
->setData($data); // set data (keys = database column name)
$sqlManager->update($sqlQuery);
// connect to server "localhost", db "test" with user/pass "rootuser/rootuser"
$dbInstance = \Simplon\Db\DbInstance::MySQL('localhost', 'test', 'rootuser', 'rootuser');
// ##############################################
// query
$dbInstance->ExecuteSQL('DELETE FROM foobar WHERE id = :id', ['id' => 5]);
// connect to server "localhost", db "test" with user/pass "rootuser/rootuser"
$dbInstance = \Simplon\Db\DbInstance::MySQL('localhost', 'test', 'rootuser', 'rootuser');
// ##############################################
// query
$sqlQuery = (new SqlQueryBuilder())
->setTableName('foobar') // define the table name
->setConditions(['id' => 5]); // set conditions
$sqlManager->remove($sqlQuery);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.