Download the PHP package ongom/dite-orm without Composer

On this page you can find all versions of the php package ongom/dite-orm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package dite-orm

DiteORM.

This is PHP ORM for interacting with relational database like Mysql, Sqlite, Posgre, Oracle etc. Currently, it supports only Sqlite, Mysql, Sqlserver and Postgresql databases. It allows us to keep oursevles within only PHP code instead of switching between sql and PHP code.

DiteORM uses functions and classes to generate the right sql which is needed. This means sometimes you have to adjust the setting in the php.ini to fit the database you are using.

Installation.

This can be done using one of this two ways;

1 - Download this github repository and extract it into the root of your project.

2 - Using composer by running composer require dite-orm at the root of you project.

Setup.

To get started, create a .env file at the root of your project, this is where you will add some configaration settings for dite-orm.

Setup for sqlite.

Setup for mysql, sqlserver, postgre.

First create the database example 'schooldb' then add the following code to the .env.

Other configarations that can be added to .env file.

Creating tables.

Before any step you first need to autoload the outoload.php from vendor folder.

Creating tables can be done in two ways.

1. Using existing database or other softwares to create the database.

When using other software like myql workbench or PHPmyadmin, all you need to care about is the primary key field. Primary key field name is got from the name of the table written in lowercase. ie

Then the model classes(representing each table) are defined like below.

2. Using Dite **Schema to create the database.**

Add the following code below the require statement.

The above code defines a table called users with the following fields.

You can go ahead and add a post table. Below is the overall code on how to create three tables (users, posts, status) including foreign keys.

Note:

Run the code by openinng your file in the browser. This will create the table in the database.

After the tables has bean created, You can open .env and change RUN_SCHEMA = 0 or else the tables will try to be recreated.

1. Creating an intermidate table.

The intemediate table has a convention of creating it inorder for Dite to understand. You have to concatenate the two table names. For example teachers and courses tables, the intermediate table will be teachers_courses and the primary key feild will be teachers_courses_id . The intermediate table must be created like below.

Meaning of each of the methods used for building the table.

Field constrains

Querying the database.

This section will teach us how to create, read, update and delete record.

Create new record.

Creating a new user into users table as shown below.

Don't pass the primary key feild, created_at and updated_at feild because they get feild up automatically.

The create method returns the new record created only if you are creating a single record.

Updating record.

The static method update() and updateMany() are used, they takes in two paramters, the record you want to update (id or selector) the and associative array of the new values

The update method returns the new updated record. The updateMany method returns void.

Deleting record.

Static method delete will delete a record by it's id.

Deleting many records.

Static method deleteMany will delete all the record that match the where clouse passed as paramete.

NB:

Part of the query that makes the where clause is passed as a parameter to the method

Counting the number of records that matcht the query.

Static method countRecords() is used for Counting the number of records that match the query.

Reading records from the database.

This can be done using many methods which are all discussed below. All static methods without chaining functionality that are used for reading records takes in atleast two optional parameters, the where clause array/int and the feilds you want back. The fields you want back can be passed as comma separated string value of the columns you want back OR as an array of all the feilds you want back. As shown below

join

There are several ways of joining two tables.

There are methods for other type of joins.

These methods end with get() and where clause is either passed as parameter in array or integer form or chain where() method but not both

::findByPk().

For getting a single record by primary key, it works like the atatic method findById() record fro a table, it works like all()

find().

For getting all the records from a table, it works like all()

There are few more methods you can chain onto the method find() as described below.

orderBy().

Will sort the result in descending or asscending order . The values can be asc or desc for ascending and descending order respectively.

groupBy()

This will group the result by the suplied feild. groupBy() takes in a string parameter.

select().

This will select only the spacified feilds. The parameter is either string or arrays.

limit().

This is used to spacify the number of record you want to fetch. It defaults to 12

skip() or offset().

Both of these do the same thing. They are used to spacify the number of records that will be skiped. It defaults to 0

A combination of skip and limit can be used for paginating your result

pagination.

Pagination helps to query only a slice of records from the database. It has two methods;

The above query will return something like below

Using Model class to query data.

Pass the name of the table to the model constrctor if you want to query using the Model class

You can chain any valid method like select, join, group, etc.

Joining tables.

join().

Earlier we looked at joins but we were able to join only two tables using the static methods, now lets join more than two tabes. This are the different types of joins which are avaiable; join(), innerJoin, leftJoin(), rightJoin().

Three tables will be involved in this join, user, post and comments. You can join over 20 differnt tables together using any of the above types of join and apply pagination, select, border by , etc like below

joinOn

This will require you to pass the name of the toble you are joining and the condition on which you are joining

There are also other methods for joining like;

Where clause.

The where clause is passed as a parameter in the following methods.

you can also chain the where() method on the following methods

It can be passed in the following ways

1. Passing an integer.

When you pass an integer to methods like findById() or findBypk() or delete(), the integer is primary id of the of the record you will get back

The above code will return a single record whose primary id is 2.

2. Passing an associative array.

When you pass an associative array to methods like findOne() or all(), the array generate the query as bellow

3. Passing nested associative array.

Sometimes you want to apply operators like <, >, <=, >=, =, like, etc. this is done the following ways

Instead of using ':', you can use '$', for example, the output of this code is the same.

4. Passing associative array where key is $and or :and.

This will only write queries in which the where clause is separated by AND.

5. Passing associative array where key is $or or :or.

This will only write queries in which the where clause is separated by OR.

6. Passing associative array where key is $nand or :nand.

This will negate the entire :and.

7. Passing associative array where key is $nor or :nor.

This will negate the entire :nor.

The same way, putting n just after $ or : in the operator will negate that part of the query,

Passing the same column name more than one times.

If the same key is going to appear more than once, normally associative array will only pick up the key which is written last, to deal with this kind of behavior , you have to append a leading underscore (_) before the column name in the array key, this is demonstrated below.

You will have to append many underscores if the column name is repeating many times in that same associative array.

List of available operators for the where clause.

Operators Sparcles Symbol Example
= $eq or := ['name'=>[':eq' => 'tom']] OR ['name'=>[':=' => 'tom']]
< $< or :lt ['age'=>[':lt' => 18]]
> $> or :gt ['age'=>[':gt' => 18]]
>= $>= or :gte ['price'=>[':gte' => 1000]]
<= $<= or :lte ['price'=>[':eq' => 50]]
Like $like ['name'=>[':like'=>'%micheal']] or ['name'=>[':like'=>'%cheal%']]
Regexp :regexp ['name'=>[':regexp'=>'^mich']] or ['name'=>[':regexp'=>'cheal$']]
In :in ['name'=>[':in' => ['tom','mike', 'joy']]]
Between :btn or :between ['age'=>[':btn' => [20,30]]]
Null null ['age'=>'null']
Not Null not null ['age'=>'not null']
Not < $n< or :nlt ['age'=>[':nlt' => 18]]
Not > $n> or :ngt ['age'=>[':ngt' => 18]]
Not >= $n>= or :ngte ['price'=>[':ngte' => 1000]]
Not <= $n<= or :nlte ['price'=>[':neq' => 50]]
Not Like :nlike ['name'=>[':nlike'=>'%micheal']] or ['name'=>[':nlike'=>'%cheal%']]
Not In :nin ['name'=>[':nin' => ['tom','mike', 'joy']]]
Not Between :nbtn or :nbetween ['age'=>[':nbtn' => [20,30]]]
And $and [':and'=>[ 'age'=>10, 'name' =>tom ]]
Not And $nand [':nand'=>[ 'age'=>10, 'name' =>tom ]]
Or $or [':or'=>[ 'age'=>10, '_age' =>20 ]]
Not or $nor [':nor'=>[ 'age'=>10, '_age' =>20 ]]
Not Regexp $nregexp ['name'=>[':nregexp'=>'^mich']] or ['name'=>[':nregexp'=>'cheal$']]

Relationships.

This will establish connection between some tables, for example if you have a post, you can easily get its comments, or if you have a user you can get all his posts. There are three types of relationships you can use here,

1. One To One relationship.

One user has one credit card and a credit card belongs to one user. To establish a One To One relationship here , you have to create one function in the Users class and CreditCards calss defination as shonw below.

2. One To Many relationship.

The code will be as below.

3. Many To Many relationship.

This will only work if you had created an intermediate table for the two tables. The intemediate table has a convention of creating it inorder for Dite to understand. You have to concatenate the two table names. For example teachers and courses tables, the intermediate table will be teachers_courses and the primary key feild will be teachers_courses_id .The intermediate tabble must be created like below.

Each time you create a teacher or a course remember to update the intermediate table.

Let's define the relationship.

NB On to any relationship, you can chain any valid method chain exept ->findByPk()

Dropping database table

This is done using the static method drop() like below. It returns a boolean , true for successful deleting and false for failure to delete the table.

Thanks from Dite


All versions of dite-orm with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ongom/dite-orm contains the following files

Loading the files please wait ....