Download the PHP package hstanleycrow/easyphpdbcore without Composer

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

English | Español

EasyPHPDBCore

Lightweight PDO-based database layer for PHP, with a simple CRUD Model and prepared statements everywhere.

Requirements

Runtime dependency: psr/log. A PSR-3 logger is optional; without one, errors are simply thrown as exceptions.

Installation

Quick example

Every write uses prepared statements with bound values, so array keys become column names and array values become bound parameters. Never interpolate user input into query() strings; pass it through the bindings instead.

Custom read queries

getRecords() accepts positional or named bindings:

Optional logging

Any PSR-3 logger can be injected as the last constructor argument of the connection and the model (or the record classes). When omitted, a NullLogger is used and failures are only thrown.

Error handling

All failures throw typed exceptions instead of printing anything:

Both extend hstanleycrow\EasyPHPDBCore\Exception\DatabaseException, so you can catch either one specifically or the base class for all database errors.

Public API

Model

Method Description
__construct(IConnection $connection, ?LoggerInterface $logger = null) Build a model. Subclasses set protected ?string $table.
create(array $fieldsList): self Insert a row. Keys are columns, values are bound.
lastInsertId(): ?int Id generated by the last create().
query(string $query): self Set a raw SELECT to run with getRecords().
getRecords(array $bindings = []): array Run the current query and return rows as associative arrays.
getById(int\|string $id): ?array SELECT * by primary key; null if not found.
update(array $updateFields, array $whereConditions): self Update rows matching all where conditions.
delete(array $whereConditions): self Delete rows matching all where conditions.
beginTransaction() / commit() / rollback(): void Transaction control on the underlying PDO.

Connection

Class Description
Connection\MySQLPDOConnection Opens a real PDO MySQL/MariaDB connection.
Connection\MockConnection No-op connection for tests.
Connection\MySQLEnvConfig / MySQLEnvCharsetConfig Read credentials/charset from an env array.
Connection\IConnection / IConfig / ICharsetConfig Interfaces to plug in your own implementations.

Record classes (used internally by Model, usable standalone)

CreateRecords, ReadRecords, UpdateRecords, DeleteRecords each expose an execute(...) method and share the same (IConnection, string $table, ?LoggerInterface) constructor shape (ReadRecords takes the query instead of a table).

Testing

The test suite runs against an in-memory SQLite database, so no MySQL server is required.

License

MIT — see LICENSE.


All versions of easyphpdbcore with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
psr/log Version ^3.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 hstanleycrow/easyphpdbcore contains the following files

Loading the files please wait ...