Download the PHP package anax/database without Composer

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

Anax Database

Latest Stable Version Join the chat at https://gitter.im/canax/database

Build Status CircleCI

Build Status Scrutinizer Code Quality Code Coverage

Maintainability Codacy Badge

Anax Database module as a database abstraction layer (DBA) for wrapping PHP PDO with an additional layer of utilities and ease of use together with ability to use configuration file and attach into an Anax installation as a servide in $di.

The module is tested using MySQL and SQLite.

There are separate modules for a Database Query Builder in anax\database-query-builder and a Database Active Record in anax\database-active-record.

Table of content

Install

You can install the module from anax/database on Packagist using composer.

You can then copy the default configuration files as a start.

Development

To work as a developer you clone the repo and install the local environment through make. Then you can run the unit tests.

Class, interface, trait

The following classes exists.

Class, interface, trait Description
Anax\Database\Database Wrapper class for PHP PDO with enhanced error handling and extra utilities.
Anax\Database\DatabaseDebug An alternative class that can be used for debugging database related issues.

Exceptions

All exceptions are in the namespace Anax\Database\Exception\. The following exceptions exists and may be thrown.

Exception Description
Exception General module specific exception, for example when connection fail.

Configuration file

This is a sample configuration file. It is usually stored in config/database.php when used together with Anax.

You can use if-statements within the configuration file to serve different configurations for local development environment, staging and or production environment.

DI service

The database is created as a framework service within $di. The following is a sample on how the database service is created through config/di/db.php.

The setup callback works like this.

  1. The database object is created.
  2. The configuration file is read.
  3. The configuration is applied.

Access as framework service

You can access the database module as a framework service.

Create a connection

You must connect to the database before using it.

You may call $db->connect() many times, the connection is however only made once, the first time, so it is safe to call the method several times.

Perform a SELECT query

You connect and perform the query which returns a resultset.

The contents of $res is depending on the configuration key which default is set to "fetch_mode" => \PDO::FETCH_OBJ,.

You can also separate executeFetchAll() into two separate commands execute() and fetchAll().

Fetch versus FetchAll

With fetchAll() you fetch all matching rows in an array. When no matching rows are found you get en ampty array.

With fetch() you get the first item in the resultset. You may use this when your resultset only contain one row.

The content of $res is now an object of type \StdClass and you access the resultset columns by their name, for example $res->id.

FetchClass

You can fetch the resultset into an object instantiated from a specified class.

The resultset is inserted into a new object of the class "\Anax\SomeClass".

There is also executeFetchAllClass() which fetches an array of all matching rows as new objects of the class.

FetchInto

You can fetch the resultset into an existing object as public properties.

The resultset is inserted into the object $obj.

Perform an INSERT, UPDATE, DELETE query

These queries, that updates the database, uses $db->execute() and does not return a resultset.

Last insert id

You can check the last inserted id when doing INSERT where the primary key is auto generated.

Row count, affected rows

You can check how many rows that are affected by the last INSERT, UPDATE, DELETE statement.

Throw exception on failure

Exception are in general thrown as soon as something fails.

The exception is module specific Anax\Database\Exception\Exception and contains details from the error message from the PDO layer, either from the statement or from the PDO-object, depending on what type of error happens.

Dependency

No particular dependencies. The module is usually used within an Anax installation but can also be used without Anax.

License

This software carries a MIT license. See LICENSE.txt for details.


All versions of database with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 anax/database contains the following files

Loading the files please wait ....