SimpleMySQL is a lightweight π‘ and minimalistic π¦ PHP library for working with MySQL using mysqli
.
Itβs designed to make SQL interaction in your PHP projects easier, cleaner, and safer β no frameworks required!
- π Safe prepared statements with parameter binding
- π Full transaction control:
start()
/finish()
/stop()
- π Fetch one or many rows easily
- π Read cached JSON files for fast offline access
- β Get server variables like
max_connections
- π UTF-8 charset by default
- π§© Fully standalone β no dependencies!
require_once 'database.php';
$db = new SimpleMySQL();
$user = $db->fetch("SELECT * FROM users WHERE id = ?", [1]);
echo $user['name'];
$users = $db->fetchAll("SELECT * FROM users WHERE status = ?", ['active']);
foreach ($users as $user) {
echo $user['email'] . "<br>";
}
$db->execute("UPDATE users SET role = ? WHERE id = ?", ['admin', 3]);
$db->execute("INSERT INTO logs (message) VALUES (?)", ['User added']);
$id = $db->lastInsertId();
$db->start();
try {
$db->execute("DELETE FROM sessions WHERE user_id = ?", [2]);
$db->execute("UPDATE users SET status = ? WHERE id = ?", ['inactive', 2]);
$db->finish(); // β
commit
} catch (Exception $e) {
$db->stop(); // β rollback
}
$data = $db->readCache('cache/data.json');
if ($data) {
foreach ($data as $row) {
echo $row['title'] . "<br>";
}
}
echo "Max Connections: " . $db->getVariable("max_connections");
$db->close();
- You need a lightweight PHP tool to connect to MySQL β
- You donβt want heavy frameworks β
- You want safety and clarity π
- You just want to get things done π§
MIT β free to use and modify.
Built with β€οΈ by Temirkhan
@temirkhanrustemov β’temirkhan.onyx@gmail.com