Download the PHP package josemmo/umysql without Composer
On this page you can find all versions of the php package josemmo/umysql. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download josemmo/umysql
More information about josemmo/umysql
Files in josemmo/umysql
Package umysql
Short Description Uncomplicated MySQL Abstraction Layer
License MIT
Homepage https://github.com/josemmo/umysql
Informations about the package umysql
Uncomplicated MySQL
UMySQL is an extremely simple PHP library for communicating with MySQL databases with ease while keeping overhead to a bare minimum. It aims to be an almost 1-to-1 and modern replacement for SafeMySQL.
It doesn't provide any ORM, migration, events, caching, etc. functionality: Just the bare minimum to get you started.
Installation
First of all, make sure your environment meets the following requirements:
- PHP 7.1 or higher
- MySQLi extension
Then, you should be able to install this library using Composer:
Usage
Creating a new instance
Typically, you'll want to create a new database instance using connection options:
You can also connect to a UNIX socket:
As an alternative to options, you can wrap a mysqli
instance around a database connection:
Writing queries
UMySQL supports various placeholders to safely replace values into queries:
?s
for strings, decimals and dates?i
for integers?n
for identifiers (table and column names)?a
for arrays of strings?u
for maps (associative arrays), useful in UPDATE queries?p
for already parsed query parts
Here are some common examples on how to use them:
Fetching results
The database instance comes with built-in helpers for retrieving rows from the database in a straightforward manner:
$db->getAll()
to get all rows in a result set$db->getRow()
to get only the first row ornull
in case of an empty result set$db->getCol()
to get the values from the first column of a result set$db->getOne()
to get the first column from the first row orfalse
in case of an empty result set
Some examples are:
Executing other queries
For non-SELECT and more advanced queries, UMySQL has a $db->query()
method that returns a custom Result
instance.
Typically, you'll use this method when you don't care about the result of an operation or when there's no result set:
Result instances are also useful in UPDATE/DELETE operations to get the number of affected rows:
Similarly, you can get the last insert ID of an auto-increment column in INSERT operations:
These instances can also be used to read a result set at your own pace:
Running the test suite
If you want to contribute to this project, please make sure to run the tests before committing new changes.
Tests are run against a MySQL database, so you'll need to define the following environment variables beforehand:
DB_HOSTNAME
DB_USERNAME
DB_PASSWORD
(optional)DB_DATABASE
All versions of umysql with dependencies
ext-mysqli Version *