Download the PHP package dawidgorecki/dbal without Composer
On this page you can find all versions of the php package dawidgorecki/dbal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dawidgorecki/dbal
More information about dawidgorecki/dbal
Files in dawidgorecki/dbal
Package dbal
Short Description Database abstraction layer (DBAL) for PHP
License MIT
Homepage https://github.com/dawidgorecki/dbal-php
Informations about the package dbal
DBAL for PHP
Database Abstraction Library for PHP with ActiveRecord features. It based on PDO extension.
Requirements
- PHP 7.1.0+
- PDO driver
- Enabled extensions: pdo_pgsql and/or pdo_mysql
Installation
Installation via Composer is the recommended way to install. Add this line to your composer.json file:
or run
Usage
Configuration
Getting connection and DBAL instance
Using Connection Manager:
Using Database Factory:
Errors & Exceptions
You can turn off all exceptions thrown by DBALDatabase by setting false as second parameter in object constructor.
Getting error message and query string:
DBAL API
getPDO()
Returns a PDO instance representing a connection to a database
startTransaction()
Initiates a transaction (turns off autocommit mode)
commit()
Commits a transaction, returning the database connection to autocommit mode
rollback()
Rolls back the current transaction
fetchAll()
Returns all rows of the query result
fetchFirst()
Returns first row of the query result
fetchArray()
Returns first row of the query result as numeric indexed array
fetchAssoc()
Returns first row of the query result as associative array
fetchColumn()
Returns a single column from the first row of the query result
delete()
Deletes rows of a given table
insert()
Inserts a row into the given table
update()
Updates rows of a given table
executeQuery()
Executes a prepared statement with the given SQL and parameters and returns PDOStatement instance
updateQuery()
Executes a prepared statement with the given SQL and parameters and returns the affected rows count
prepare()
Prepare a given SQL statement and return the PDOStatement instance
quote()
Quotes a string for use in a query
lastId()
Return ID of the last inserted row
ActiveRecord
Model private properties should have the same names as columns in database table.
Naming convention
Database Table
- Plural with underscores separating words (e.g., user_details)Model Class
- Singular with the first letter of each word capitalized (e.g., UserDetail)Usage
Extend your model class with
Reven\DBAL\ActiveRecord
Create database connection
Set connection name if it's not default
Change default database table (optional)
Basic CRUD
Create
To create a new record in database (e.g. add new user) we instantiating a new object and then invoking the save() method.
Read
These are your basic methods to find and retrieve records from your database.
Update
To update you would just need to find a record first and then change one of attributes.
Delete
That will call SQL query to delete the record in your database.
License
Licensed under the MIT license. (http://opensource.org/licenses/MIT)
All versions of dbal with dependencies
ext-pdo Version *