Download the PHP package sugiphp/database-ext without Composer

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

SugiPHP\DatabaseExt

Version 1.0

Extends PHP's PDO/PDOStatement with PSR-14 event dispatching and a read/write connection state guard.

Components

Class Description
PdoExt PDO subclass that dispatches events around exec()/query() and enforces the read/write state
PdoStatementExt PDOStatement subclass (used automatically by PdoExt) that dispatches events around execute()
PdoInterface Interface listing the standard PDO methods
PdoStatementInterface Interface listing the standard PDOStatement methods
Event\* PSR-14 event classes dispatched by PdoExt/PdoStatementExt (see below)

Usage

By default PDO::ATTR_ERRMODE is set to PDO::ERRMODE_EXCEPTION (unless overridden via the $options array), so failed statements throw a PDOException and the ExecError/QueryError/ExecuteError events fire as documented below.

Events

Pass a PSR-14 EventDispatcherInterface to observe queries (e.g. for logging or profiling):

Event Dispatched by When
AfterConnect PdoExt After the connection is established
BeforeExec / AfterExec PdoExt::exec() Around a successful exec() call
ExecError PdoExt::exec() When exec() throws a PDOException
BeforeQuery / AfterQuery PdoExt::query() Around a successful query() call
QueryError PdoExt::query() When query() throws a PDOException
BeforeExecute / AfterExecute PdoStatementExt::execute() Around a successful prepared-statement execute() call
ExecuteError PdoStatementExt::execute() When execute() throws a PDOException
Rejected PdoExt::exec()/query(), PdoStatementExt::execute() Instead of any of the above, when the statement is rejected by the read/write state guard (see below)

On failure, the *Error event is dispatched instead of the matching After* event, and the original PDOException is then rethrown.

Each After*/*Error event carries a getBefore() accessor returning the matching Before* event instance. PdoEvent also exposes setAttribute(string $key, mixed $value) / getAttribute(string $key): mixed, so a listener can stash arbitrary data (e.g. a profiler job) on the Before* event and retrieve it via getBefore()->getAttribute(...) when the matching After*/*Error event fires, without keeping its own state between events.

Logging and profiling example

SugiPHP\DatabaseExt only depends on the PSR-14 EventDispatcherInterface, not on a full PSR-14 implementation, so the simplest way to log and time every statement is to implement that interface directly with a single class that stashes a start time on the Before* event and reads it back on the matching After*/*Error event:

Swap the LoggerInterface calls for whatever profiler/APM hook you use (e.g. push a span per query) — the point is that setAttribute()/getAttribute() on the Before* event is the mechanism for carrying state (a timer, a profiler span, a request ID, ...) from before a statement runs to after it finishes or fails.

Read/write state

PdoExt::setState() restricts which statements may run:

In STATE_READ_ONLY, statements starting with ALTER, CREATE, DELETE, DROP, GRANT, INSERT, MERGE, RENAME, REPLACE, REVOKE, TRUNCATE, or UPDATE are rejected — exec()/query()/execute() return false and a Rejected event is dispatched instead of the usual Before*/After* pair, so a listener can audit or monitor blocked write attempts. This is a best-effort, first-keyword check, not a SQL parser — it will not catch a write hidden inside a CTE, a comment-prefixed statement, or a stacked query. That is what the driver-enforced read-only mode below is for; it stops those writes at the connection level even when this check lets them through. In STATE_UNAVAILABLE, all statements are rejected the same way.

This keyword check is an app-level guard and only covers statements issued through PdoExt/PdoStatementExt. As a second, driver-enforced layer, setState() also puts the underlying connection itself into (or out of) a read-only mode when the driver supports it:

Driver Command issued in STATE_READ_ONLY / STATE_UNAVAILABLE Command issued in STATE_READ_WRITE
pgsql SET default_transaction_read_only = on SET default_transaction_read_only = off
mysql SET SESSION TRANSACTION READ ONLY SET SESSION TRANSACTION READ WRITE
sqlite PRAGMA query_only = ON PRAGMA query_only = OFF

Other drivers rely solely on the app-level keyword check above.


All versions of database-ext with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
psr/event-dispatcher Version ^1.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 sugiphp/database-ext contains the following files

Loading the files please wait ...