Download the PHP package modularr/database without Composer
On this page you can find all versions of the php package modularr/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package database
Database
An easy to use class for Database queries in PHP.
- API
- Connections
- Examples
- Install
API
See Below for usage.
Connections
This class lets you connect to PDO whichever way you choose, This maximizes flexibility by letting you simply give us your already existing object, or by using our class as your primary Database package and asking for the PDO object if you need to pass it to other libraries.
Connection Syntax
You can connect using multiple syntax to make it easy to use, available both in the __construct()
as well as connect()
You can either use an associative array or the default which uses reverse order to let you define the most important values first, and lets you default irrelevant values such as host or type to it's defaults ('mysql' and 'localhost')
Via Instantiation
Via Method
Via Existing PDO Object
Usage and Use Case
A facade is optional but has all the same functionality of the main class.
Regular Use Case
Facades Use Case
Create Facade from PDO Object
Connect Via Facade
Use Case
Query
This is a query with bind parameters. First argument is the statement, second argument is an array of parameters (optional)
Note: We passed the query into a variable for later re-use.
Quote
Escaping in PDO adds quotes around the escaped string, which is an issue if you try doing a LIKE query:
PDO does not provide a way to turn off quotes around escaped strings so, we created a function that simply removes the quotes (first and last characters). This returns a string similar to the old mysql_real_escape_string function.
Please note that this requires you to start adding quotes yourself. Escaping is the default when you bind parameters in PDO. As such, escaping is turned on by default as per the original function (passthrough).
Fetch and Safe Fetch
This is regular returned object. You still need to apply htmlspecialchars yourself.
This is safe returned object. htmlspecialchars is applied to all the objects's properties.
Num Rows
Data Examples
Installation
via Composer:
composer require modularr/database
Or install like so:
Manual:
- Download Release Or copy file manually
- Include Main.php found under src/ (this includes both Database.php and Facade.php)