PHPackages                             jabarihunt/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. jabarihunt/mysql

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

jabarihunt/mysql
================

A simple class that handles MySQL database instances with support for both TCP and Socket connections. I created this class as a standard way to interact with MySQL databases from within other projects with very low overhead. I will personally use it as a dependency in those projects, but it's perfectly capable of being used as a standalone handler.

v1.5.3(3y ago)0891MITPHPPHP &gt;=8.0

Since Feb 24Pushed 3y ago1 watchersCompare

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

READMEChangelog (10)DependenciesVersions (18)Used By (1)

MySQL Handler
=============

[](#mysql-handler)

A simple class that handles MySQL database instances with support for both TCP and Socket connections. I created this class as a standard way to interact with MySQL databases from within other libraries with very low overhead, but it's perfectly capable of being used as a standalone handler.

Getting Started
---------------

[](#getting-started)

### Prerequisites

[](#prerequisites)

You will need to have the following environment variables present (usually done with a .env file):

```
MYSQL_HOST="localhost"
MYSQL_DATABASE="manevia_db"
MYSQL_USER="root"
MYSQL_PASSWORD="secretPassword"
MYSQL_SOCKET="NULL"
MYSQL_PORT=3306
```

Depending on how you load environment variables, you may be able to reference already defined variables when setting the required environment variables above. This helps prevent having to maintain values in multiple locations. For example:

```
DATABASE_HOST="localhost"
DATABASE_DATABASE="manevia_db"
DATABASE_USER="roo"
DATABASE_PASSWORD="secretPassword"
DATABASE_SOCKET="NULL"
DATABASE_PORT=3306

MYSQL_HOST="${DATABASE_HOST}"
MYSQL_DATABASE="${DATABASE_NAME}"
MYSQL_USER="${DATABASE_USER}"
MYSQL_PASSWORD="${DATABASE_PASSWORD}"
MYSQL_SOCKET="${DATABASE_SOCKET}"
MYSQL_PORT=${DATABASE_PORT}
```

### Installing

[](#installing)

##### Via Composer

[](#via-composer)

Run the following command in the same directory as your composer.json file:

`composer require jabarihunt/mysql`

##### Via Github

[](#via-github)

1. Clone this repository into a working directory: `git clone git@github.com:jabarihunt/mysql.git`
2. Include or require the MySQL class in your project...

```
require('/path/to/cloned/directory/src/MySQL.php');
```

...or if using an auto-loader...

```
 use jabarihunt/MySQL;
```

Usage
-----

[](#usage)

This class does not require instantiation since it uses the singleton design pattern for connections. You may simply begin using the available public methods. If none of the methods are called, a database connection is never created. You may alias the class as another name using `use/as`, as demonstrated below:

```
use jabarihunt/MySQL as DB;

/*
 * QUERY THE DATABASE WITH A PREPARED STATEMENT (RECOMMENDED)
 *
 * prepare($query, $paramValues, $paramTypeString = NULL):
 * CONVENIENCE METHOD THAT RETURNS ARRAY OF DATA FOR QUERIES THAT RETURN A RESULT SET, THE NUMBER OF AFFECTED ROWS FOR ALL
 * OTHER QUERIES, OR FALSE ON ERROR.  $paramTypeString IS OPTIONAL, ALL VALUES WILL BE SENT AS STRINGS IF NOT PROVIDED.
 */

    $data = DB::prepare('SELECT name, email FROM users WHERE age > ? AND status = ? AND days_active >= ?', [357, 'retired', 30], 'isi');

/*
 * QUERY THE DATABASE AS A STANDARD QUERY
 *
 * query($query):
 * CONVENIENCE METHOD THAT RETURNS AN ARRAY OF DATA FOR QUERIES THAT RETURN A RESULT SET, TRUE ON SUCCESS, OR FALSE ON ERROR.
 */

    $data = DB::query("SELECT name, email FROM users WHERE age > 69 AND status = 'retired' AND days_active >= 30");

/*
 * SANITIZE VALUES WHEN NOT USING PREPARED STATEMENTS
 * THIS METHOD USES PHP filter_var() SANITIZATION BASED ON THE DATA TYPE
 */

    $string = 'Am I a good string or a naughty string?';

    $string = DB::sanitize($string, DB::DATA_TYPE_INTEGER);     // All characters removed since sanitizing as an int data type!
    $string = DB::sanitize($string);                            // String remains since method defaults to DB::DATA_TYPE_TEXT
    $string = DB::sanitize(NULL);                               // Null values are converted to an empty string before sanitizing

    // CLASS DATA TYPES ARE BASED ON MYSQL DATA TYPES.  DATA TYPES ARE DECLARED IN THE CLASS AS SHOWN BELOW:

        const DATA_TYPE_INTEGER  = ['tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'bit'];
        const DATA_TYPE_REAL     = ['float', 'double', 'decimal'];
        const DATA_TYPE_TEXT     = ['char', 'varchar', 'tinytext', 'text', 'mediumtext', 'longtext'];
        const DATA_TYPE_BINARY   = ['binary', 'varbinary', 'blob', 'tinyblob', 'mediumblob', 'longblob'];
        const DATA_TYPE_TEMPORAL = ['date', 'time', 'year', 'datetime', 'timestamp'];
        const DATA_TYPE_SPATIAL  = ['point', 'linestring', 'polygon', 'geometry', 'multipoint', 'multilinestring', 'multipolygon', 'geometrycollection'];
        const DATA_TYPE_OTHER    = ['enum', 'set'];

/*
 * GET MySQLi OBJECT
 */

    $mysqlObject = DB::getMySQLObject();

/*
 * MYSQL DUMP -> CONVENIENCE METHOD FOR DUMPING A DATABASE SOMEWHERE ON THE MACHINE | USE WITH CAUTION!!!
 * CREATES MYSQL DUMP FILE AT GIVEN PATH WITH FORMAT: _--_.sql
 */

    DB::backup('path/to/my/backup/folder');
```

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

[](#contributing)

1. Fork Repository
2. Create a descriptive branch name
3. Make edits to your branch
4. Squash (rebase) your commits
5. Create a pull request

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

Established project with proven stability

 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

Every ~33 days

Recently: every ~2 days

Total

17

Last Release

1370d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2807764?v=4)[Jabari J. Hunt](/maintainers/jabarihunt)[@jabarihunt](https://github.com/jabarihunt)

---

Top Contributors

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

---

Tags

databasemysql

### Embed Badge

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

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

###  Alternatives

[rah/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

64401.8k10](/packages/rah-danpu)

PHPackages © 2026

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