1. Go to this page and download the library: Download rancoud/database 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/ */
rancoud / database example snippets
composer
// Create a configurator
$params = [
'driver' => 'mysql',
'host' => 'localhost',
'user' => 'root',
'password' => '',
'database' => 'test_database'
];
$databaseConf = new Configurator($params);
// No singleton
$database = new Database($databaseConf);
// With named instances
$database = Database::setInstance($databaseConf, 'primary');
$count = $database->count("SELECT COUNT(*) FROM users");
// Output be like
3
// insert with parameters and get last insert id
$params = ['username' => 'adam', 'ranking' => 100];
$lastInsertId = $database->insert("INSERT INTO users (username, ranking) VALUES (:username, :ranking)", $params, true);
// Output be like
4
// update with parameters and get the number of affected rows
$params = ['username' => 'adam', 'id' => 4];
$affectedRowsCount = $database->update("UPDATE users SET username = :username WHERE id = :id", $params, true);
// Output be like
1
// delete with parameters and get the number of affected rows
$params = ['id' => 4];
$affectedRowsCount = $database->delete("DELETE FROM users WHERE id = :id", $params, true);
// Output be like
1
$database->startTransaction();
if (isOk()) {
$database->commitTransaction();
} else {
$database->rollbackTransaction();
}
Database::setInstance($databaseConfA, 'primary');
Database::setInstance($databaseConfB, 'secondary');
/** A few moments later **/
$db = Database::getInstance('secondary');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.