1. Go to this page and download the library: Download m/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/ */
m / db example snippets
$db = \m\Db::open([
"host" => "db01.internal",
"user" => "app",
"pass" => "secret",
"db" => "shop",
]);
$query = "SELECT * FROM cart WHERE user_id = :user_id";
$params = [
"user_id" => 123,
];
$rows = $db->read($query, $params);
// returns array of associative arrays
$query = "UPDATE cart SET updated = NOW() WHERE id = :id";
$params = [
"id" => 456,
];
$affected = $db->write($query, $params);
// returns number of affected rows
interface DbInterface
{
public static function open($config);
public function config($key = null, $value = null);
public function read($query, array $params = []);
public function write($query, array $params = []);
}
use \m\Db;
$db = Db::open("mysql://username:password@host/db");
$db = Db::open($_ENV["DATABASE_URL"]);
$currHost = $db->config("host"); // get current config value
$oldValue = $db->config("host", "db02.internal"); // change one item, returns old value
$config = $db->config(); // get all config values
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.