Download the PHP package peterujah/db-controller without Composer
On this page you can find all versions of the php package peterujah/db-controller. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download peterujah/db-controller
More information about peterujah/db-controller
Files in peterujah/db-controller
Package db-controller
Short Description Php PDO databse wrapper.
License MIT
Homepage https://github.com/peterujah/db-controller
Informations about the package db-controller
DBController
DBController is a PHP PDO wrapper that provides a convenient way to interact with a database using the PDO extension.
Installation
You can install the package via Composer by running the following command:
USAGES
To use DBController, follow these easy steps.
- Create an instance of the DBController class by passing the database configuration as an array or a path to a configuration file that returns array.
Or extend \Peterujah\NanoBlock\DBController
to set your connection details like below
Initialize your custom class
Now run query select, insert, update, delete etc.. using prepare statment
Or run query select, insert, update, delete etc.. using query
Customization
Customize the configuration or enable debugging as needed.
Error Handling
DBController provides error handling for database operations. You can retrieve the error information using the error()
or errorInfo()
methods.
Debugging
You can enable debugging mode to get more detailed information about the executed statements by calling the dumpDebug()
method.
Methods
Use the various methods provided by the DBController class to interact with the database.
Options | Description |
---|---|
prepare(string) | Call "prepare" with sql query string to prepare query execution |
query(string) | Call "query" width sql query without "bind" and "param" |
bind(param, value, type) | Call "bind" to bind value to the pdo prepare method |
param(param, value, type) | Call "param" to bind parameter to the pdo statment |
execute() | Execute prepare statment |
rowCount() | Get result row count |
getOne() | Get one resault row, this is useful when you set LIMIT 1 |
getAll() | Retrieve all result |
getInt() | Gets integer useful when you select COUNT() |
getAllObject() | Gets result object |
getLastInsertedId() | Gets list inserted id from table |
free() | Free database connection |
dumpDebug() | Dump debug sql query parameter |
errorInfo() | Print PDO prepare statment error when debug is enabled |
error() | Print connection or execution error when debug is enabled |
setDebug(bool) | Sets debug status |
setConfig(array) | Sets connection config array |
conn() | Retrieve DBController Instance useful when you call "setConfig(config)" |
Configuration format
Connection config array example
Contributing
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request.