Skip to content

πŸ“Š The Database class is a versatile PHP tool using mysqli for database management. It handles essential CRUD operations (Create, Read, Update, Delete) and includes methods for user authentication and password hashing, making database interactions and user management simple and secure.

Notifications You must be signed in to change notification settings

Iqbolshoh/php-database-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“Œ Database Manager - PHP MySQL Wrapper

πŸš€ 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.

Banner Image

✨ Features

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

πŸ“₯ Installation

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.

πŸ› οΈ Usage

1️⃣ Initialize the Database

require_once 'Database.php';
$db = new Database();

2️⃣ Running Queries

πŸ” Select Data

$users = $db->query("SELECT * FROM users WHERE email = ?", ['[email protected]']);
print_r($users);

βž• Insert Data

$db->query("INSERT INTO users (name, email) VALUES (?, ?)", ['Iqbolshoh Ilhomjonov', '[email protected]']);

✏️ Update Data

$db->query("UPDATE users SET email = ? WHERE id = ?", ['[email protected]', 3]);

❌ Delete Data

$db->query("DELETE FROM users WHERE id = ?", [3]);

3️⃣ Transactions

$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();
}

🚨 Error Handling

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();
}

πŸ“œ License

This project is open-source and available under the MIT License.

πŸ–₯ Technologies Used

PHP MySQL .htaccess Git .env

🀝 Contributing

🎯 Contributions are welcome! If you have suggestions or want to enhance the project, feel free to fork the repository and submit a pull request.

πŸ“¬ Connect with Me

πŸ’¬ I love meeting new people and discussing tech, business, and creative ideas. Let’s connect! You can reach me on these platforms:

About

πŸ“Š The Database class is a versatile PHP tool using mysqli for database management. It handles essential CRUD operations (Create, Read, Update, Delete) and includes methods for user authentication and password hashing, making database interactions and user management simple and secure.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published