Download the PHP package krugozor/database without Composer

On this page you can find all versions of the php package krugozor/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package database

Other languages:


Getting the Library

You can download it as an archive, clone it from this site, or install via composer (packagist.org link):

What is krugozor/database?

krugozor/database is a PHP >= 8.0 class library for simple, convenient, fast, and secure work with MySQL databases, using the PHP extension mysqli.

Why do you need a custom class for MySQL when PHP already has PDO abstraction and the mysqli extension?

The main drawbacks of all libraries for working with MySQL in PHP are:

Solution: krugozor/database — a class for working with MySQL

  1. Eliminates verbosity — instead of 3 or more lines of code to execute a single query when using the "native" library, you write just one.
  2. Escapes all parameters going into the query body according to the specified placeholder type — reliable protection against SQL injections.
  3. Does not replace the functionality of the "native" mysqli adapter, but simply complements it.
  4. Extensible. Essentially, the library provides only a parser and SQL query execution with guaranteed protection against SQL injections. You can inherit from any library class and, using both library mechanisms and mysqli and mysqli_result mechanisms, create the methods you need.

What the krugozor/database library is NOT

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

The krugozor/database library is none of these. It's just a convenient tool for working with regular SQL within the MySQL DBMS — and nothing more!

What are placeholders?

Placeholdersspecial typed markers that are written in the SQL query string instead of explicit values (query parameters). The values themselves are passed "later", as subsequent arguments to the main method that executes the SQL query:

SQL query parameters passed through the placeholder system are processed by special escaping mechanisms, depending on the placeholder type. This means you no longer need to wrap variables in escaping functions like mysqli_real_escape_string() or cast them to numeric types, as was done before:

Now writing queries has become easy, fast, and most importantly, the krugozor/database library completely prevents any possible SQL injections.

Introduction to the Placeholder System

The types of placeholders and their purposes are described below. Before getting acquainted with placeholder types, you need to understand how the library mechanism works.

The PHP Problem

PHP is a weakly typed language, and an ideological dilemma arose during the development of this library. Imagine we have a table with the following structure:

and the library MUST (for some reason, possibly beyond the developer's control) execute the following query:

In this example, there's an attempt to write a null value to the not null text field name, and a boolean false to the numeric field flag. What should we do in this situation?

Given these questions, it was decided to implement two operating modes in this library.

Library Operating Modes

The following conversions are allowed in Mysql::MODE_TRANSFORM mode:

What placeholder types are available in the library?

?i — integer placeholder

SQL query after template conversion:

WARNING! If you're working with numbers that exceed PHP_INT_MAX, then:

?d — floating-point number placeholder

SQL query after template conversion:

WARNING! If you're using the library to work with the double data type, set the appropriate locale so that the decimal separator is the same at both the PHP level and the DBMS level.

?s — string type placeholder

Argument values are escaped using the mysqli::real_escape_string() method:

SQL query after template conversion:

?S — string type placeholder for substitution in the SQL LIKE operator

Argument values are escaped using the mysqli::real_escape_string() method + escaping of special characters used in the LIKE operator (% and _):

SQL query after template conversion:

?nNULL type placeholder

The value of any arguments is ignored; placeholders are replaced with the string NULL in the SQL query:

SQL query after template conversion:

?A* — associative set placeholder from an associative array, generating a sequence of key = value pairs

where the * character is one of the placeholders:

the conversion and escaping rules are the same as for the single scalar types described above. Example:

SQL query after template conversion:

?a* — set placeholder from a simple (or also associative) array, generating a sequence of values

where * is one of the types:

the conversion and escaping rules are the same as for the single scalar types described above. Example:

SQL query after template conversion:

?A[?n, ?s, ?i, ...] — associative set placeholder with explicit type and argument count specification, generating a sequence of key = value pairs

Example:

SQL query after template conversion:

?a[?n, ?s, ?i, ...] — set placeholder with explicit type and argument count specification, generating a sequence of values

Example:

SQL query after template conversion:

?f — table or field name placeholder

This placeholder is intended for cases when the table or field name is passed in the query as a parameter. Field and table names are enclosed in backticks:

SQL query after template conversion:

Delimiting Quotes

The library requires the programmer to follow SQL syntax. This means the following query will not work:

— the ?s placeholder must be enclosed in single or double quotes:

SQL query after template conversion:

For those accustomed to working with PDO, this will seem strange, but implementing a mechanism that determines whether to enclose a placeholder value in quotes or not is a very non-trivial task requiring writing an entire parser.

Examples of Working with the Library

See the file ./console/tests.php


All versions of database with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
ext-mysqli Version *
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package krugozor/database contains the following files

Loading the files please wait ...