Skip to content

Latest commit

 

History

History
145 lines (124 loc) · 5.48 KB

README.md

File metadata and controls

145 lines (124 loc) · 5.48 KB

📌 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 = ?", ['iilhomjonov777@gmail.com']);
print_r($users);

➕ Insert Data

$db->query("INSERT INTO users (name, email) VALUES (?, ?)", ['Iqbolshoh Ilhomjonov', 'iilhomjonov777@gmail.com']);

✏️ Update Data

$db->query("UPDATE users SET email = ? WHERE id = ?", ['iqbolshoh123@gmail.com', 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: