Welcome to PhpStratum’s documentation for MySQL and MariaDB!

PhpStratum is a set of PHP packages for loading stored procedures into your application’s database and invoking those stored procedures conveniently from your application using an automatically generated wrapper class. Currently, PhpStratum is available for the following database management systems:

This is the documentation of PhpStratum for MySQL and MariaDB. This documentation is self contained and doesn’t require any knowledge from any other documentation.

Further Reading

You have the following options for further reading:

  • Continue reading this documentation for MySQL and MariaDB.
  • Reading a broader documentation about the concepts of Stratum Projects in other programming languages than PHP.
  • Reading the general documentation of PhpStratum.
  • Reading the documentation of PhpStratum for SQLite. This documentation is self contained and doesn’t require any knowledge from any other documentation.

Table of Contents

Getting Started

In this chapter you will learn how to install PhpStratum, loading stored routines, and generating the data layer. The data layer is a class for conveniently invoking your stored routines in your PHP code.

Installing PhpStratum

The preferred way to install PhpStratum is using composer:

composer require setbased/php-stratum-mysql
composer require setbased/php-stratum

The first line installs the MySQL and MariaDB backend and the second line installs the frontend (a.k.a the CLI) of PhpStratum.

Running PhpStratum

You can run PhpStratum from the command line:

./vendor/bin/stratum

If you have set bin-dir in the config section in composer.json you must use a different path.

Installing & Uninstalling PhpStratum

Installing PhpStratum

The preferred way to install PhpStratum is using composer:

composer require setbased/php-stratum-mysql
composer require setbased/php-stratum

The first line installs the MySQL and MariaDB backend and the second line installs the frontend (a.k.a the CLI) of PhpStratum.

Running PhpStratum

You can run PhpStratum from the command line:

./vendor/bin/stratum

If you have set bin-dir in the config section in composer.json you must use a different path.

For example:

{
  "config": {
    "bin-dir": "bin/"
  }
}

then you can run PhpStratum from the command line:

./bin/stratum

Uninstalling PhpStratum

Remove PhpStratum from your project with composer:

composer remove setbased/php-stratum-mysql
composer remove setbased/php-stratum

An Example

The PhpStratum Config File

This chapter is the specification of the stratum config file.

For most projects the stratum config file must added to the VCS and distributed to the production environment of your project (unless you have some other mechanism for loading stored routines into your production database).

The stratum config file is a JSON, XML, YML or INI file and consist out of five sections which we discuss in detail in the sections below. Throughout this manual we are using INI file.

The stratum section

The stratum section is mandatory and holds one variable only:

backend (mandatory)
The fully qualified name of the class that implements the required backend. The backend must be a child class of SetBased\Stratum\Backend\Backend. The backend of PhpStratum for MySQL and MariaDB is implemented in SetBased\Stratum\MySql\Backend\MySqlBackend.

The database section

The database section is mandatory and holds the parameters to connect to the MySQL or MariaDB instance.

host (mandatory)
The host were the MySQL or MariaDB instance is running.
user (mandatory)
The user name. The user must have the create routine privilege.
password (mandatory)
The password of user.
database (mandatory)
The schema (database) with your application tables.
port (optional)
The port number for connecting to the MySQL or MariaDB instance. Default value is 3306.

The constants section

The constants section is optional and holds the variables for constants based on column sizes and constants defined in PHP available in the sources of stored routines.

columns (mandatory)
A plain text file with table column names and their corresponding constant names.
class (mandatory)
The class defining constants.
prefix (mandatory)
The default prefix to used when generating a constant name based on the size of a column.

The loader section

The loader section is mandatory and holds the variables for loading your stored routines into the database.

sources (mandatory)

Holds the pattern with sources of stored routines. This variable can have two forms:

  • A wildcard pattern like lib/psql/**/*.psql.
  • A filename like file:stratum-sources.txt. The filename is relative to the directory of the stratum config file. The file holds a wildcard pattern per line.
metadata (mandatory)
The path to the file were the metadata of stored routines must be stored in JSON format. This metadata is used to determine which stored routines must loaded or removed from the database and provide information for wrapper generator.
sql_mode (mandatory)
The SQL mode under which the stored routines must run.
character_set (mandatory)
The (default) character set under which the stored routine must run.
collate (mandatory)
The (default) collate under which the stored routine must run.

Note: the SQL mode, character set, and collate under which a store routine runs is determined when the stored routine is defined and not inherited from the session that call the stored routine.

The wrapper section

The wrapper section is optional and holds variables for generating the wrapper class (a.k.a. the data layer).

parent_class (mandatory)
The fully qualified name of the parent class of the wrapper class. PhpStratum for MySQL and MariaDB provides class SetBased\Stratum\MySql\MySqlDataLayer.
mangler_class (optional)
The fully qualified name of the class for converting the name of a stored routine into the name of the method for calling the stored routine. This class must implement SetBased\Stratum\Middle\NameMangler\NameMangler. Fr converting stored routines with underscores use class \SetBased\Stratum\Middle\NameMangler\PsrNameMangler.
wrapper_class (mandatory)
The fully qualified name of the generated wrapper class.
wrapper_file (mandatory)
The path the file where to source of the wrapper class must be stored.
strict_types (optional, default 1)
If 1 the wrapper class will enable strict mode. If 0 strict mode is disabled.

The PhpStratum Program

The PhpAudit program is a Symphony console application with five additional commands:

  • constants
  • crud
  • loader
  • stratum
  • wrapper

We discuss the additional commands in the sections below.

Some commands provide additional output when in verbose mode (-v). All commands show the queries been executed in very verbose mode (-vv).

_images/screenshot-help.png

The constants command

The crud command

The loader command

The stratum command

The wrapper command

License

The project is licensed under the MIT license.