Download the PHP package simplon/db without Composer
On this page you can find all versions of the php package simplon/db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package db
_ _ _ _ ___(_)_ __ ___ _ __ | | ___ _ __ __| | |__ / __| | '_ ` _ \| '_ \| |/ _ \| '_ \ / _` | '_ \ \__ \ | | | | | | |_) | | (_) | | | | | (_| | |_) | |___/_|_| |_| |_| .__/|_|\___/|_| |_| \__,_|_.__/ |_|
Simplon/Db
Version 1.1.0
Intro
Most of my projects require data from at least one type of database. In order to handle all communications I wrote some interface libraries which help me to deal with my daily coding fun. I worked with all supported databases hence all these interfaces were written.
For the last months I am running mostly with a MySQL setup supported with Redis as a cache store. I worked with Memcached before which I believe is stable on what its supposed to do. I closed the Couchbase chapter for now although I believe its a great idea. However, I wasnt really happy with its performance respectively its immature behaviour compared to e.g. Redis.
Supported databases
Dependecies
Big parts of all libraries will work with PHP 5.3. However since I am transitioning to PHP 5.4 you will find partly PHP 5.4 only code. This will grow depending how much time I find. Find all dependencies below:
- PHP >= 5.4.8
- MySQL: EasyPDO
- Redis: phpiredis (PHP bindings) for hiredis (C-Client for Redis)
- Couchbase: PHP Client Library with C-Client library
- Memcached: libevent
Installing
You can install Simplon/Db either via package download from github or via composer install. I encourage you to do the latter:
Depending on which database you would like to use pay attention to the above listed dependencies.
1. Usage MySQL
Lets do some coding given that all desired databases and its dependencies were installed.
1.1 MySQL connection
Lets create a MySQL connection instance:
Another way to create a mysql instance is via the . This class creates the instance and holds it as Singleton throughout runtime within a pool of other connections - in case you have to keep more than one connection:
1.2 MySQL query
When querying a database we have again two options. The first option is to access the database directly via EasyPDO which is a PDO wrapper:
The other option requires the use of the . In order to use this class we need to pass a builder pattern class, , to communicate with our database. What advantage does that offer? Well in case that we want to do more things with our query before sending it off we encapsule it as an object within the . From there on we could pass it throughout our application to add more data or alike before sending the query finally to the database:
What both options have in common are the named parameters which are identified by the conditions- / data-array keys.
1.3 MySQL insert/update
The way how to insert/update datasets differs for both options. Again see the following examples for better understanding:
Here goes our SqlManager solution with SqlQueryBuilder:
Difference is that for the latter method we don't need to write any repetitive SQL which in turn results in better maintenance and general code overview.
1.4 MySQL remove datasets
From time to time we also need to remove a couple of datasets. Again, two examples:
SqlManager with SqlQueryBuilder:
1.5 MySQL summary: direct access
- Connect (both options are valid):
-
- Returns: DbInstance
- Fetch all found data:
-
- Returns an assoc. array
-
- Returns an array
-
- Returns an object
-
- Fetch by steps:
-
- Returns an iterator pointer which is essential for very big result sets
-
- Fetch one column value:
-
- Returns the first selected column
-
- Insert data:
-
- Returns insert-id or null. FALSE when failed
-
- Update data:
-
- Returns FALSE when failed
-
- Remove data:
-
- Returns FALSE when failed
-
1.6 MySQL summary: access via SqlManager with SqlQueryBuilder
- Connect (both options are valid):
-
- Returns: DbInstance
- SqlManager instance:
- Fetch all found data:
-
- Returns an assoc. array
- Fetch by steps:
-
- Returns an iterator pointer which is essential for very big result sets
- Fetch one column value:
-
- Returns the first selected column
- Insert data:
-
- Returns insert-id or null. FALSE when failed
- Update data:
-
- Returns FALSE when failed
- Remove data:
-
- Returns FALSE when failed
2. Usage Redis
Work in progress ...
Changelog
Version 1.1.0
- Refactored Redis library since it had >3000 LOC
- Redis library has been seperated by its commands
- RedisManager offers references to all command classes