π This project, developed by Iqbolshoh Ilhomjonov, is a simple and secure PHP database wrapper class that uses MySQLi for database interactions. It provides an easy-to-use interface for executing queries, fetching results, and managing transactions efficiently.
- π Secure MySQLi connection
- β‘ Supports prepared statements
- π Fetch results as an associative array or object
- π Transaction management (begin, commit, rollback)
- β Error handling with exceptions
- π οΈ Convenient helper methods for inserting, updating, and deleting data
You can clone the repository from GitHub:
git clone https://github.com/Iqbolshoh/php-database-manager.git
Or simply include the Database.php
file in your project and create an instance of the Database
class.
require_once 'Database.php';
$db = new Database();
$users = $db->query("SELECT * FROM users WHERE email = ?", ['[email protected]']);
print_r($users);
$db->query("INSERT INTO users (name, email) VALUES (?, ?)", ['Iqbolshoh Ilhomjonov', '[email protected]']);
$db->query("UPDATE users SET email = ? WHERE id = ?", ['[email protected]', 3]);
$db->query("DELETE FROM users WHERE id = ?", [3]);
$db->beginTransaction();
try {
$db->query("UPDATE accounts SET balance = balance - ? WHERE id = ?", [100, 1]);
$db->query("UPDATE accounts SET balance = balance + ? WHERE id = ?", [100, 2]);
$db->commit();
} catch (Exception $e) {
$db->rollback();
echo "Transaction failed: " . $e->getMessage();
}
If an error occurs, an exception will be thrown. You can catch it like this:
try {
$db->query("SELECT * FROM nonexistent_table");
} catch (Exception $e) {
echo "Database error: " . $e->getMessage();
}
This project is open-source and available under the MIT License.
π― Contributions are welcome! If you have suggestions or want to enhance the project, feel free to fork the repository and submit a pull request.
π¬ I love meeting new people and discussing tech, business, and creative ideas. Letβs connect! You can reach me on these platforms: