PHPackages                             mohiwalla/php-mysql - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mohiwalla/php-mysql

ActiveLibrary[Database &amp; ORM](/categories/database)

mohiwalla/php-mysql
===================

A PHP library for MySQL connections, executing queries, calling procedures, and fetching results with error handling.

1.0.0(1y ago)311MITPHPPHP &gt;=7.0

Since Jul 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mohiwalla/php-mysql)[ Packagist](https://packagist.org/packages/mohiwalla/php-mysql)[ Docs](https://github.com/mohiwalla/php-mysql)[ RSS](/packages/mohiwalla-php-mysql/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

PHP-MySQL Database Wrapper
==========================

[](#php-mysql-database-wrapper)

This is a simple PHP class that provides a wrapper around the MySQL database using the MySQLi extension. It abstracts the database connection and query execution, making it easier to interact with a MySQL database in your PHP projects.

Features
--------

[](#features)

- Establishes a connection to the MySQL database using the provided credentials.
- Executes SQL queries using prepared statements, which helps prevent SQL injection attacks.
- Provides a method to execute stored procedures with parameters.
- Fetches all rows from a MySQL result set and applies an optional callback to each row.
- Automatically closes the database connection when the object is destroyed.

### Installation

[](#installation)

To install the utility, you can use Composer. Add the following to your `composer.json` file:

```
{
	"require": {
		"mohiwalla/php-mysql": "1.0.0"
	}
}
```

Then run:

```
composer install
```

OR just run this command directly:

```
composer require mohiwalla/php-mysql
```

Usage
-----

[](#usage)

Here's an example of how to use the `DB` class:

```
require __DIR__ . "/vendor/mohiwalla/php-mysql/index.php";

$con = new DB("localhost", "root", "", "shoppy");
$query = "SELECT * FROM users;";
$result = $con->query($query);

while ($row = mysqli_fetch_object($result)) {
    echo print_r($row, true);
}
```

Methods
-------

[](#methods)

### `__construct(string $host, string $user, string $password, string $database)`

[](#__constructstring-host-string-user-string-password-string-database)

Initializes a new instance of the `DB` class, establishing a connection to the MySQL database using the provided host, user, password, and database name. If the connection fails, the script exits with an error message.

### `query(string $query, ...$values)`

[](#querystring-query-values)

Executes a SQL query using a prepared statement with the given parameters. This function prepares and executes the query, handling the binding of the provided parameters to the query and returning the result object.

### `procedure(string $name, ...$values)`

[](#procedurestring-name-values)

Executes a stored procedure with the given name and parameters. This function constructs a SQL query to call the stored procedure using placeholders for the parameters, then prepares and executes the query.

### `fetchAll($result, callable $callback = null)`

[](#fetchallresult-callable-callback--null)

Fetches all rows from a MySQL result set and applies an optional callback to each row. This method iterates over the result set, fetches each row as an associative array, optionally applies a user-defined callback to each row, and collects the rows in an array.

Contributing
------------

[](#contributing)

If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the [GitHub repository](https://github.com/your-username/php-mysql-wrapper).

License
-------

[](#license)

This project is licensed under the [MIT License](LICENSE).

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

673d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c7b06a95da770c35d84624836fc73a20e42882addc3552244b472eb4d5580b80?d=identicon)[mohiwalla](/maintainers/mohiwalla)

---

Top Contributors

[![mohiwalla](https://avatars.githubusercontent.com/u/121000462?v=4)](https://github.com/mohiwalla "mohiwalla (4 commits)")

---

Tags

databasemysqlmysqliphp mysqlcrulmysql apimysqli utility

### Embed Badge

![Health badge](/badges/mohiwalla-php-mysql/health.svg)

```
[![Health](https://phpackages.com/badges/mohiwalla-php-mysql/health.svg)](https://phpackages.com/packages/mohiwalla-php-mysql)
```

###  Alternatives

[sergeytsalkov/meekrodb

The Simple PHP/MySQL Library

341387.0k10](/packages/sergeytsalkov-meekrodb)[ezsql/ezsql

Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.

86946.7k](/packages/ezsql-ezsql)[stefangabos/zebra_database

An advanced, compact and lightweight MySQL database wrapper library, built around PHP's MySQLi extension.

11812.0k](/packages/stefangabos-zebra-database)[go/db

Database library

6624.1k](/packages/go-db)[krugozor/database

PHP class library for simple, convenient, fast and safe work with MySql database, using PHP mysqli extension and imitation of prepared queries.

392.5k](/packages/krugozor-database)[dabble/dabble

Lightweight wrapper and helpers for MySQLi

1210.4k](/packages/dabble-dabble)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
