Download the PHP package hxgf/dbkit without Composer
On this page you can find all versions of the php package hxgf/dbkit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package dbkit
Short Description PHP functions to handle database connection and CRUD operations with PDO.
License MIT
Homepage https://github.com/hxgf/dbkit
Informations about the package dbkit
DB Kit
Vanilla PHP functions to handle database connection and CRUD operations with PDO.
Installation
Easy install with composer:
Usage
db::init($settings)
Initializes the database connection. The output from this function should be assigned to a global 'database' variable.
db::insert($table, $input)
Sanitizes parameters and inserts an array of data into a specific table.
Returns the id field of the record created.
db::find($table, $criteria, $options)
Sanitizes parameters and retrieves a specific record(/s) from a specific table, building a query with SELECT *.
Returns an array with the the data and total number of records.
db::get() and db::fetch() are also available as aliases to db::find(), and behave the exact same way.
Raw Queries
Raw SQL queries can be used by sending a raw parameter like this:
db::update($table, $input, $criteria)
Sanitizes parameters and updates an array of data for a specific record(/s).
db::delete($table, $criteria)
Sanitizes parameters and deletes a specific record(/s).
db::create_placeholders($criteria)
Creates placeholders and sanitizes data for query building. This function is used to sanitize parameters for all functions.
It returns an array with a string of generated placeholders (where), and an array of the actual data to be used in the query (data).
An example of how it is used to prepare and execute a db::find() query:
Using PDO methods
The $GLOBALS['database'] variable is just an initialized PDO object, so it's possible to use any native PDO methods if needed.
For example:
