Skip to content

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!

Notifications You must be signed in to change notification settings

DreamerView/simple-mysql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ› οΈ SimpleMySQL β€” Lightweight MySQL Library for PHP

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!


✨ Key Features

  • πŸ” 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!

πŸš€ Quick Start

πŸ“¦ Initialize the class


require_once 'database.php';
$db = new SimpleMySQL();

πŸ” Fetch a single row


$user = $db->fetch("SELECT * FROM users WHERE id = ?", [1]);
echo $user['name'];

πŸ“„ Fetch multiple rows


$users = $db->fetchAll("SELECT * FROM users WHERE status = ?", ['active']);
foreach ($users as $user) {
    echo $user['email'] . "<br>";
}

πŸ“ Execute insert / update / delete


$db->execute("UPDATE users SET role = ? WHERE id = ?", ['admin', 3]);

πŸ†” Get last inserted ID


$db->execute("INSERT INTO logs (message) VALUES (?)", ['User added']);
$id = $db->lastInsertId();

πŸ” Transaction example


$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
}

πŸ“₯ Read data from JSON cache


$data = $db->readCache('cache/data.json');
if ($data) {
    foreach ($data as $row) {
        echo $row['title'] . "<br>";
    }
}

βš™ Get MySQL server variable


echo "Max Connections: " . $db->getVariable("max_connections");

❎ Close connection


$db->close();

βœ… When to Use It?

  • 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 🧠

πŸ“„ License

MIT β€” free to use and modify.

Built with ❀️ by Temirkhan
@temirkhanrustemov β€’ temirkhan.onyx@gmail.com

About

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!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages