Download the PHP package gyde/mysql-object-model without Composer
On this page you can find all versions of the php package gyde/mysql-object-model. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gyde/mysql-object-model
More information about gyde/mysql-object-model
Files in gyde/mysql-object-model
Package mysql-object-model
Short Description PHP ORM
License MIT
Homepage https://github.com/gyde/MySQL-Object-Model
Informations about the package mysql-object-model
MySQL-Obejct-Model
A PHP Object Model using MySQL as backend via PDO. Allows fast scaffoling of Models with a high performance MySQL specific backend. First version is available, then more information regarding installation, use and namespacing will follow. Memcache and Static cache has been added for MOMBase and MOMSimple
Table of Contents
- Version
- Usage
- Classes
- Caveats
- Tools
Version
This version is considered stable and will be version tagged 1.0 once its been field tested with php7.3!
Current projects using this project:
- Solaris - mobilspejd.dk - Scout race navigation system)
- DOG - roskilde-festival IT deployment tool
- Intranet - Ordbogen A/S intranet
No guareentes are given when using this code, but all suggestions and bugreports are welcome.
Usage
Example table
Class definition
A simple example on the usage of MOMSimple
You only need to define the optional columns you want to use for easy (constant safe) access, object member variables will be created from database table definition using SQL lookup.
Connecting SQL using PDO
Creating and saving objects
Get object by primary key
Fetching objects
All
Filtering
A small guide to filtering using where clauses on many or one object
Many
Fetch some User objects by SQL where clause
Functionality like the above example should in general be placed inside the object class like so:
One
Fetch one User object by SQL where clause
Modifying object
When fetching objects
You can overwrite the default load method to change member variables after an object is fetched from the database, you might want to "cast" all timestamps and datetimes into DateTime objects
Classes / Types
MOMBase.class.php
The generic / factory class which all object models extends from. This contains generic query function and requires that extending classes implements needed methods.
MOMSimple.class.php
A simple scaffoling class for MySQL tables with ONE column as primary key
MOMCompound
A compound scaffoling class for MySQL tables with SEVERAL columns as primary key
Caveats
Here is a list of common tips, tricks and caveats currently in the MOM system.
On update / default value columns
If you create a table with a column that has a default "current timestamp" value or "on update" property beware that this column is controlled completely by MOM and can't be updated by setting a value on public class variable. The column is omitted from any insert or update statements that MOM performs.
Tests (PHPUnit)
Tests has been designed using PHPUnit and will create and droppe tables as needed within the docker env. In order to run the tests, the following needs to be satisfied:
- A running docker-ce environment
Build the docker environment using ./docker/build_container ./docker/bootstrap_container /absolute/path/to/MySQL-Object-Model/
Run ./run_tests to start the tests within the docker env. ./run_tests
build_mom
Shell script to "build" MOM using first provided argument as namespace.
MOM files will be placed in a folder called build with namespace my\name\space. Additional slashes are needed due to shell escaping