Download the PHP package gajus/doll without Composer
On this page you can find all versions of the php package gajus/doll. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package doll
Short Description Extended PDO with inline type hinting, deferred connection support, logging and benchmarking.
License BSD-3-Clause
Homepage https://github.com/gajus/doll
Informations about the package doll
Doll
Extended PDO with inline type hinting, deferred connection support, logging and benchmarking.
Single Parameter Constructor
PDO::__construct is using Data Source Name (DSN) string to describe the connection. PDO DSN implementation does not include user, password and driver options.
Doll instance is described using DataSource
object:
Deferred Connection
PDO will establish a connection to the database upon initialization. If application initializes PDO during the bootstrap, but does not execute queries (e.g. request that is served from cache), the connection is unnecessary.
Doll will not connect to the database upon initialization:
The connection is deferred until either of the following methods are invoked:
- PDO::prepare()
- PDO::exec()
- PDO::query()
- PDO::beginTransaction()
- PDO::commit()
- PDO::rollBack()
- PDOStatement::execute()
Default Attributes
Attribute | PDO | Doll |
---|---|---|
PDO::ATTR_ERRMODE |
PDO::ERRMODE_SILENT |
PDO::ERRMODE_EXCEPTION |
PDO::ATTR_EMULATE_PREPARES |
false |
true |
PDO::ATTR_DEFAULT_FETCH_MODE |
PDO::FETCH_BOTH |
PDO::FETCH_ASSOC |
PDO::ATTR_STATEMENT_CLASS |
PDOStatement |
Gajus\Doll\PDOStatement |
Attribute | Reason |
---|---|
PDO::ATTR_ERRMODE |
Enables method chaining. |
PDO::ATTR_EMULATE_PREPARES |
PDO_MYSQL will take advantage of native prepared statement support present in MySQL 4.1 and higher. It will always fall back to emulating the prepared statement if the driver cannot successfully prepare the current query. |
PDO::ATTR_DEFAULT_FETCH_MODE |
More convenient. |
PDO::ATTR_STATEMENT_CLASS |
Required for the extended type hinting implementation. |
Values for attributes not in the table do not differ.
Method Chaining
PDOStatement::execute() returns a boolean value indicating the state of the transaction, e.g.
However, if you are using PDO::ERRMODE_EXCEPTION error handling strategy, the output of execute
is redundant.
Doll forces PDO::ERRMODE_EXCEPTION
error handling strategy, while execute
method returns an instance of \Gajus\Doll\PDOStatement
. This allows further method chaining, e.g.
Extended Type Hinting
Inline Type Hinting
PDOStatement::bindValue() method allows to set the parameter type. However, the syntax is verbose:
Doll allows inline type hinting:
Doll implementation supports all of the parameter types:
Name | Parameter Type |
---|---|
b |
PDO::PARAM_BOOL |
n |
PDO::PARAM_NULL |
i |
PDO::PARAM_INT |
s |
PDO::PARAM_STR |
l |
PDO::PARAM_LOB |
Inferred Type Hinting
When parameter name is "id" or ends with "_id", unless an explicit parameter type is set, Doll will use PDO::PARAM_INT
, e.g.
Is equivalent to:
You can explicitly set the parameter type:
You can disable the inferred type hinting:
Parameter Marker Reuse
Using Doll, you can reuse the named parameter markers in your prepared statements, e.g.
The native PDO implementation does not support it. It will raise the following error:
PDOException: SQLSTATE[HY093]: Invalid parameter number
Logging and Benchmarking
Doll supports query and statement execution logging. To enable logging, you need to set \Gajus\Doll\PDO::ATTR_LOGGING
attribute to true
.
The log output contains the following information about each query:
"execution_duration" and "query" are retrieved from SHOW PROFILES. Doll will automatically run diagnostics every 100 executions to overcome the limit of 100 queries.