1. Go to this page and download the library: Download jr-cologne/db-class 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/ */
jr-cologne / db-class example snippets
use JRCologne\Utils\Database\DB;
use JRCologne\Utils\Database\QueryBuilder;
$db = new DB(new QueryBuilder);
if ($db->connect('mysql:host=localhost;dbname=db-class-example;charset=utf8', 'root', 'root')) {
echo 'Successfully connected to database';
} else {
echo 'Connection failed';
}
if ($db->connected()) {
echo 'Successfully connected to database';
} else {
echo 'Connection failed';
}
$data = $db->table('users')->select('*')->retrieve();
if ($data === false) {
echo 'Ops, something went wrong retrieving the data from the database!<br>';
} else if (empty($data)) {
echo 'It looks like there is no data in the database!<br>';
} else {
echo 'Successfully retrieved the data from the database!<br>';
echo '<pre>', print_r($data, true), '</pre>';
}
$inserted = $db->table('users')->insert('username, password', [
'username' => 'test',
'password' => 'password'
]);
if ($inserted) {
echo 'Data has successfully been inserted';
} else if ($inserted === 0) {
echo 'Ops, some data could not be inserted';
} else {
echo 'Inserting of data is failed';
}
if (
$db->table('users')->update(
[
'username' => 'test123', // new data
'password' => 'password123',
],
[
'username' => 'test', // where clause
'password' => 'password',
]
)
) {
echo 'Data has successfully been updated';
} else {
echo 'Updating data failed';
}
if ($db->table('users')->delete([
'username' => 'test' // where clause
])) {
echo 'Data has successfully been deleted';
} else {
echo 'Deleting data failed';
}
// include all files
aces
use JRCologne\Utils\Database\DB;
use JRCologne\Utils\Database\QueryBuilder;
// instantiate database class with query builder
$db = new DB(new QueryBuilder);
// connect to database
$db->connect('mysql:host=localhost;dbname=db-class-example;charset=utf8', 'root', 'root');
// prepare query like with PDO class
$stmt = $db->prepare("SELECT * FROM `users`");
// execute query
$stmt->execute();
// fetch all results
$results = $stmt->fetchAll();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.