Download the PHP package effectra/db without Composer

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

Effectra\Database

Effectra\Database is a PHP package that provides database connection and query execution functionality. It offers a convenient interface for interacting with different database drivers and executing common database operations.

Installation

You can install the Effectra\Database package via Composer. Simply run the following command:

Usage

Connection

To establish a database connection, you need to create an instance of the Connection class and call the connect method. The connect method retrieves the database configuration from the provided configuration file and returns a PDO object representing the database connection.

By default, the Connection class supports MySQL and SQLite database drivers. You can easily add support for additional database drivers by implementing the DriverInterface and configuring the Connection class accordingly.

Query Execution

Once you have established a database connection, you can execute queries using the DB class. The DB class provides methods for executing common database operations such as select, insert, update, and delete.

The DB class provides a fluent interface for building and executing queries. You can chain methods to construct complex queries easily.

Error Handling

If an error occurs during query execution, the DB class will throw a DatabaseException. You can catch and handle this exception to gracefully handle database errors.

Model

  1. Namespace: The model is part of the Effectra\Database namespace.

  2. Traits: The model uses the ModelEventTrait trait.

  3. Properties:

    • $connection: An instance of the DBInterface representing the database connection.
    • $schema: An array containing the schema of the model.
    • $entries: An array containing the entries of the model.
    • $table: The name of the table associated with the model.
    • $primaryKey: The primary key for the model (default is 'id').
    • $keyType: The data type of the primary key (default is 'int').
    • $incrementing: Indicates if the model's ID is auto-incrementing (default is true).
    • const CREATED_AT and const UPDATED_AT: Constants representing the names of "created at" and "updated at" columns.
    • $options: Additional options for the model.
    • private static $query: A static property to store the last executed database query.
  4. Constructor:

    • The constructor sets the table name if not provided.
  5. Methods:
    • isEntriesCreated(): Checks if entries have been created for the model.
    • createModelStructure(): Creates the structure of the model, including schema and entries.
    • getDatabaseConnection(): Gets a new database connection instance.
    • createSchema(): Creates the schema for the model by fetching metadata from the database.
    • isSchemaCreated(): Checks if the schema has been created for the model.
    • createEntriesFromSchema(): Creates entries for the model based on the schema.
    • Various methods for setting, getting, and manipulating options.
    • getSchema($property): Gets the schema entry for a specific property.
    • getEntries(): Gets the entries for the model.
    • hasEntry($property): Checks if a specific entry exists in the model.
    • getEntry($property): Gets the value of a specific entry in the model.
    • setEntries($entries): Sets the entries for the model.
    • setEntry($property, $value): Sets a specific entry for the model.
    • removeEntry($property): Removes a specific entry from the model.
    • Various magic methods (__invoke, __set, __get, __toString, __isset, __unset, __callStatic, __call) for dynamic property access and method calls.
    • toArray(): Converts the model to an array representation.
    • toJson($flags = 0, $depth = 512): Converts the model to its JSON representation.
    • save(): Saves the model to the database.
    • update(): Updates the model in the database.
    • transaction($callback, ...$args): Performs a model operation in a transaction.
    • saveInTransaction($data = []): Saves the model in a transaction.
    • updateInTransaction(): Updates the model in a transaction.
    • Methods for retrieving models from the database (get, all, limit, find, findBy, search, where, between).
    • Methods for deleting models from the database (delete, deleteById, deleteByIds, deleteByIdsInTransaction).
    • truncate(): Truncates the model's table.
    • lastInsertId(): Gets the last inserted ID for the model.
    • validateId($id): Validates a model ID.
    • setQuery($query): Sets the query instance for the model.
    • getQueryUsed(): Gets the query instance used by the model.
    • getQueryUsedAsString(): Gets the query instance used by the model as a string.
    • dd(): Dumps the model class using Symfony's VarDumper.

Overall, this model provides a flexible and extensible foundation for database interactions in a PHP application. It includes features for CRUD operations, query building, and transaction management. Additionally, it leverages traits for handling model events and uses Symfony's VarDumper for debugging purposes.

Basic Usage

create Model

Retrieve a Record

Update a Record

Save a Record

Contributing

Contributions to the Effectra\Database package are welcome. If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on the GitHub repository.

License

The Effectra\Database package is open-source software licensed under the MIT license. See the LICENSE file for more information.


All versions of db with dependencies

PHP Build Version
Package Version
Requires effectra/event-dispatcher Version ^1.0
bmt/noun-converter Version ^1.0
effectra/sql-query Version ^2.0
effectra/data-optimizer Version ^1.0
symfony/var-dumper Version ^6.0
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 effectra/db contains the following files

Loading the files please wait ....