Download the PHP package llwebsol/easy-db without Composer
On this page you can find all versions of the php package llwebsol/easy-db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package easy-db
EasyDB
A Simple Wrapper for PDO
To get the most out of this library, every table in your database should have a primary key called id.
Getting Started
using composer
1. Create a Config
Accepted db_type options:
- mysql
- pgsql
- sqlite*
- sqlsrv*
*currently untested
Complete List of Options:
2. Get a DB Instance
Use the ConnectionPool to retrieve a database instance for a given configuration.
3. Querying the Database
Once you have an instance of the DB class, there are several helper methods available to you
- Query
accepts any database query you desire, with an optional array of bound parameters
returns a Generator for iterating through your result set
- QueryOne
helper for getting a single record from the database
Returns the record as an array, (not wrapped in a generator)
- Insert
Insert a record into a given table Returns the last inserted id
- Update
Update a record in a given table returns the number of rows affected
- Save
this is just an alias for insert/update if the $data has an 'id' field it will update, otherwise it will insert
- Delete
Delete a record from a given table
returns the number of rows affected or false if invalid
- Delete Where
Delete records from a given table that meet the conditions of the where clause Returns the number of rows deleted
- Update Where
Update records from a given table that meet the conditions of the where clause Returns the number of rows updated
- Find In
Returns a Generator with all records in table where $column_name IN ( $in_array )
SQL Equivalent:
4. Events
You can add event listeners for any stage of a database interaction
Supported Events:
- ON_ERROR
- BEFORE_QUERY
- AFTER_QUERY
- BEFORE_UPDATE
- AFTER_UPDATE
- BEFORE_INSERT
- AFTER_INSERT
- BEFORE_DELETE
- AFTER_DELETE
Helpers:
- BEFORE_SAVE ( BEFORE_INSERT and BEFORE_UPDATE)
- AFTER_SAVE (AFTER_INSERT and AFTER_UPDATE)
Examples
Echo the sql of every query that is performed
Add a user id to all inserted records
*Assumes all of your tables have a created_user column
`
*Referenced Parameters are available for BEFORE_INSERT and BEFORE_UPDATE events only
5. Transactions
You can perform multiple actions with a single transaction with the following 3 methods
- beginTransaction
- commitTransaction
- rollbackTransaction
Example: