PHPackages                             busenov/database - 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. busenov/database

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

busenov/database
================

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

v1.0.0(2y ago)05PHPPHP &gt;=7.2

Since Sep 7Pushed 2y agoCompare

[ Source](https://github.com/busenov/Database)[ Packagist](https://packagist.org/packages/busenov/database)[ Docs](https://github.com/Vasiliy-Makogon/Database)[ RSS](/packages/busenov-database/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

**[![](https://camo.githubusercontent.com/d041d61b52a635b130cd2651b45ddfc7a524e559d022ad13dbb0b7bdbba36e3b/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f656e2f7468756d622f662f66332f466c61675f6f665f5275737369612e7376672f323370782d466c61675f6f665f5275737369612e7376672e706e67)](https://camo.githubusercontent.com/d041d61b52a635b130cd2651b45ddfc7a524e559d022ad13dbb0b7bdbba36e3b/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f656e2f7468756d622f662f66332f466c61675f6f665f5275737369612e7376672f323370782d466c61675f6f665f5275737369612e7376672e706e67) [Русскоязычная документация находится тут](README_rus.md) [![](https://camo.githubusercontent.com/d041d61b52a635b130cd2651b45ddfc7a524e559d022ad13dbb0b7bdbba36e3b/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f656e2f7468756d622f662f66332f466c61675f6f665f5275737369612e7376672f323370782d466c61675f6f665f5275737369612e7376672e706e67)](https://camo.githubusercontent.com/d041d61b52a635b130cd2651b45ddfc7a524e559d022ad13dbb0b7bdbba36e3b/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f656e2f7468756d622f662f66332f466c61675f6f665f5275737369612e7376672f323370782d466c61675f6f665f5275737369612e7376672e706e67)**

---

[![](https://camo.githubusercontent.com/5c7444aa82da17aa593dac4ea672d03da0e514d8ea4afd2a9b5dc91cc9a93e5a/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f656e2f7468756d622f612f61652f466c61675f6f665f7468655f556e697465645f4b696e67646f6d2e7376672f323370782d466c61675f6f665f7468655f556e697465645f4b696e67646f6d2e7376672e706e67)](https://camo.githubusercontent.com/5c7444aa82da17aa593dac4ea672d03da0e514d8ea4afd2a9b5dc91cc9a93e5a/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f656e2f7468756d622f612f61652f466c61675f6f665f7468655f556e697465645f4b696e67646f6d2e7376672f323370782d466c61675f6f665f7468655f556e697465645f4b696e67646f6d2e7376672e706e67) Getting the Library
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#-getting-the-library)

You can [download it as an archive](https://github.com/Vasiliy-Makogon/Database/archive/master.zip), clone from this site, or download via composer ([link to packagist.org](https://packagist.org/packages/busenov/database)):

```
composer require busenov/database

```

What is `busenov/database`?
---------------------------

[](#what-is-busenovdatabase)

`busenov/database` is a PHP 8.0 class library for simple, convenient, fast and secure work with the MySql database, using the PHP extension [mysqli](https://www.php.net/en/mysqli).

### Why do we need a self-written class for MySql if PHP has a PDO abstraction and a mysqli extension?

[](#why-do-we-need-a-self-written-class-for-mysql-if-php-has-a-pdo-abstraction-and-a-mysqli-extension)

The main disadvantages of all libraries for working with the mysql database in PHP are::

- **Verbosity**
    - Developers have two options to prevent SQL injections:
        - Use [prepared queries](https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php).
        - Manually escape the parameters going into the body of the SQL query. String parameters run via [mysqli\_real\_escape\_string](https://www.php.net/manual/en/mysqli.real-escape-string.php) and the expected convert numeric parameters to the appropriate types - `int` and `float`.
    - Both approaches have huge drawbacks:
        - Prepared queries are [terribly verbose](https://www.php.net/manual/en/mysqli.prepare.php#refsect1-mysqli.prepare-examples). Use "out of the box" PDO abstraction or mysqli extension, no aggregation all methods for obtaining data from the DBMS is simply impossible - in order to get the value from the table, you need write at least 5 lines of code! And so on for every request!
        - Manual escaping of parameters going into the body of an SQL query is not even discussed. A good programmer lazy programmer. Everything should be as automated as possible..
- **Unable to get SQL query for debugging**
    - To understand why the SQL query does not work in the program, you need to debug it - find either a logical or syntax error. To find an error, you need to "see" the SQL query itself, which the database "swears" at, with parameters substituted into its body. Those. to have formed high-grade SQL. If the developer is using PDO, with prepared queries, then it's... IMPOSSIBLE! There are no most convenient mechanisms for this in native libraries [NOT PROVIDED](https://qna.habr.com/q/22669). It remains either to pervert, or to climb into the database log.

### Solution: `busenov/database` is a class for working with MySql

[](#solution-busenovdatabase-is-a-class-for-working-with-mysql)

1. Eliminates verbosity - instead of 3 or more lines of code to execute one request when using the "native" library, you write only one.
2. Screens all parameters that go to the request body, according to the specified type of placeholders - reliable protection against SQL injections.
3. Does not replace the functionality of the "native" mysqli adapter, but simply complements it.
4. Expandable. In fact, the library provides only a parser and the execution of a SQL query with guaranteed protection against SQL injections. You can inherit from any library class and use both the library mechanisms and the `mysqli` and `mysqli_result` mechanisms to create the methods you need to work with.

### What is NOT the `busenov/database` library?

[](#what-is-not-the-busenovdatabase-library)

Most wrappers for various database drivers are a bunch of useless code with a disgusting architecture. Their authors, not understanding the practical purpose of their wrappers themselves, turn them into a kind of builders queries (sql builder), ActiveRecord libraries and other ORM solutions.

The `busenov/database` library is none of the above. This is just a convenient tool for working with regular SQL within the framework MySQL DBMS - and no more!

What are placeholders?
----------------------

[](#what-are-placeholders)

**Placeholders** — special *typed markers* that are written in the SQL query string *instead of explicit values (query parameters)*. And the values themselves are passed "later", as subsequent arguments to the main a method that executes a SQL query:

```
