Download the PHP package efoft/active-records without Composer

On this page you can find all versions of the php package efoft/active-records. 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 active-records

ActiveRecords for Databases

=====

The package gives a simple and unified interface to interact with various database engines. You can operate with the same set of method independently of which database is on backend. Currently supported:

Installation


The package is intended to be used via Composer. Add this to you composer.json:

or simply run from command-line:

Initialization


The package consists of the main class ActiveRecords and some Database Handlers. When initialize the class instance you need to specify one of the Handlers. Each type of the Handler in turn requires some parameters for database connection.

! Make sure path to db file is writable.

Database preparation

Unkike MongoDB, which is schemaless and doesn't require any preparation, for SQL engines you first need to create database and tables in it. MongoDB has very convinient fiture to store sequential arrays (sets) as a field in a doc.

To emulate such feature with SQL DB, this package uses a separate database table (subtables) for every such field. So if the call to DB tries to search through such sets than related subtables are left joined. And when set modification is requested, separate queries to the subtables are being run to perform this. From performance perpective it's definately not the best solution for havy usage but acceptable for relatively small loads.

In MySQL 5.7 there is JSON type fields support so the same behavior can be achived with JSON approach in a future.

If you plan to store some information as an arrays (sets), the following steps are recommended:

  1. The main database table must use InnoDB engine since it supports foreign key contraints.
  2. For each field that will store a set, create a table with the name of the field and foreign key to the main table (see examples below).
  3. Such table must have column named 'relid' of integer type and a column named with the same word as the table itself that will store set's data.

Below are the examples of creating the main tables "table1" and the subtable "tags" that will store arrays related to the main table's records:

To add the constraint to the existing table use the following query:

If setting ON DELETE CASCADE constraint is not possible for any reasons than set the attribute:

which will activate additional routine to run each time on subtables when the records from the main table is removed. It all needed to avoid orphan records in the subtables.

Usage


The table (or collection for MongoDB) can be set once for all later operations or can be specified each time for single operation.

If you set table name via setTable it stays default table for all cases when the table is not specified explicitly in operations.

Add (insert) data

Usage: $ar->add($data, [$tablename]);

Add operation returns the id of the inserted record (if such field is used in SQL database, always returns in case of MongoDB).

If add operation returns NULL that likely mean that validation failed.

Validation

In the example above the search will run on database to check fields name and age if they already contain the same data is being tried to insert.

If validation failed you can get the error information:

Update data

Usage: $ar->update($criteria, $data, [$tblname]);

The fields age and name will be updated for the record with id 12.

The $data must be an array and can include special keys '$set', '$addToSet', '$push' and '$pull'. The meaning is equal to what they mean for MongoDB updates. If none of those keys are specified, then '$set' is assumed. Below is the example of mixed $data update:

So the values 'two' and 'jack1.jpg' will be appended to the corresponding arrays 'tags' and 'imgs' if the don't exist there yet, but 'age' will be set to 33 since in this case '$set' is assumed.

Delete records

Delete all records where age field has value 36.

Get data

There are 2 methods of usage:

All arguments are optional. Below are the description of them: ..$criteria - associative array with db field names as keys. Values may be as exact value or regexp. For MongoDB full regexp syntax is supported and is simply transfered to mongodb commands. For MySQL/SQLite the syntax is converted to SQL format, so only limited syntax is accepted:


All versions of active-records with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
efoft/query-builder Version 1.0.2
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 efoft/active-records contains the following files

Loading the files please wait ....