Download the PHP package ceus-media/database without Composer
On this page you can find all versions of the php package ceus-media/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package database
Database
PHP database access
Installation
Composer
Install this library using composer:
Within your code, load library:
Code Examples using PDO
Database Connection
Tables
Existing database tables can be declared as tables:
Table class
Table instance
Having this defined structure, you can use a table instance for reading from and writing into the database table. Hence that you need to create a database connection beforehand.
Reading an entry
Example for getting an entry by its primary key:
The result will be an object of table columns and their values, since the fetch mode is set to object-wise by table structure:
Not having the fetch mode set would result in an associated array, which is set as default fetch mode in underlaying table reader. To change the fetch see below.
Hint: There are more methods to retrive a single entry:
- getByIndex
- getByIndices
which allow to focus on foreign indices instead of the primary key.
Finding entries
A group of entries, filtered by a foreign key:
A group of entries, filtered by several foreign keys:
To get all entries, call:
which may be bad in scaling, so reduce the result set by defining limits and conditions:
Conditions can be indices or any other column.
Orders are pairs of columns and directions, like:
There are more parameters possible for each of this indexing methods, which allow:
- fields: restricting columns in result set
- grouping: apply GROUP BY
- having: apply HAVING
Counting
To count entries by a foreign key:
To count entries, filtered by several foreign keys:
To get all entries, call:
which may be bad in scaling, so reduce the result set by defining conditions:
Hint: Counting having really large MySQL tables may be slow. There is a method to count in large tables in a faster way. You will find it.
Adding an entry
Attention: For security reasons, all HTML tags will be striped. Set second parameter to FALSE to avoid that, if needed. Make sure to strip HTML tags of none-HTML columns manually!
Updating an entry
where the result will be the number of changed entries.
Attention: For security reasons, all HTML tags will be striped. Set third parameter to FALSE to avoid that, if needed. Make sure to strip HTML tags of none-HTML columns manually!
Updating several entries
where the result will be the number of changed entries.
Attention: For security reasons, all HTML tags will be striped. Set third parameter to FALSE to avoid that, if needed. Make sure to strip HTML tags of none-HTML columns manually!
Removing an entry
where the result will be the number of removed entries.
Removing several entry
where the result will be the number of removed entries.
Change fetch mode
In your table structure class, set:
where YOUR_FETCH_MODE is one of these standard PDO fetch modes:
- FETCH_ASSOC
- FETCH_NAMED
- FETCH_NUM
- FETCH_BOTH
- FETCH_OBJ
Code Examples using OSQL
Having a config file like this:
and assuming that you load things up like this:
you can connect to a database like this:
Now you can query the database like this:
The result will contain the requested rows (only one in this example):
will produce:
All versions of database with dependencies
ext-pdo Version *
ceus-media/common Version ^1.0 | 1.0.x-dev
ceus-media/cache Version ^0.5 | 0.5.x-dev