Download the PHP package parvezmrobin/db-model without Composer

On this page you can find all versions of the php package parvezmrobin/db-model. 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 db-model

DB-Model

Retrieves MySQL database instances SIMPLESTly in OOP style


Initialize

Set the database name

Retrieve All Instances

Get all the instances

Now you can access all attributes of User in an Object oriented fashion.

Do not want to retrieve all the fields? Just add an additional array or string to all() method to denote the fields you need.

Retrieve conditionally

Want to retrieve instances on condition? Use where() method and give the condition.

Retrieve single instance

Want to retrieve a single user based on id? Use find() method to simplify the action.

Note that where() and all() method returns array of instances where find() method returns a single instance.

If your primary key is not named 'id', then you have to mention it.

And obviously the columns as the last parameter.


Retrieve using relation

DB-Model Supports One to Many, Many to One and Many to Many relationship. However, you can use these methods to retrieve your One to One relation as well.

Note that oneToMany(), manyToOne() and manytoMany() are instance method. Where all(), where() and find() are static method.

One to Many

Say, your User has many Posts. So, Posts must have a user_id field to store primary key of User. The user_id field in Post is said Foreign Key. Again, id of User is said Referenced Key as it is referenced by user_id in Post. You can easily retrieve the Posts of User using oneToMany() method. The simplest form is

If primary key of User is not id, then you should guess what to pass next.

If you are clever enough, you should understand that, oneToMany() can also be used to store one to one relationship. If Settings has an one to one relationship with User, then each User will have exactly one Settings. So what are you waiting for?

Of course, you can use the rest of parameters al well.

Many to One

What if you need to get the corresponding User instance from a Post post instance? manyToOne() is here for you with same signature.

If your User has a different primary key than id, then mention that too.

Again, if you want to retrieve using inverse one to one relationship, use manyToOne() method as well.

Many to Many

To implement Many to Many relationship in database you need an intermediate table which contains foreign key of both the related tables. Suppose, Post has a many to many relationship with Tag. Then, you need an intermediate table, say post_tag which contains foreign key of Post and Tag, say post_id and tag_id. Now, your code will be

If the models have different primary key than id, then mention it next.

Insertion

To insert a Model into database, simple just create a Model instance. Set the properties. Call the store() method.

store() method has two aliases namely insert() and save() with same signature.

Updating

Create a model. Set only properties to be updated. Call update() method with table name and the condition on which the update will be performed. And you are done!

To avoid mistakes, update() method does not have a default $condition parameter.

Want to update using the primary key? Then you will prefer the updateById() method.

When your primary key is not id then you have to pass the name of primary key as the next argument.

Customizing Connection Params

There are five public static field that are used to connect with database. These are $host, $database, $username, $password, $port. The default values for these fields are

You can change these values according to your database.

Running Raw Queries

Although, not suggested, you can run raw queries using \DbModel\Query class. Simply make a \DbModel\Query instance and run your query.


All versions of db-model with dependencies

PHP Build Version
Package Version
Requires php Version ^5.3.3 || ^7.0
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 parvezmrobin/db-model contains the following files

Loading the files please wait ....