Download the PHP package oza/database without Composer
On this page you can find all versions of the php package oza/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package database
A Database package to deal with your data
- Fully Tested With Mysql Driver
- Contributors Needed
- Made without any dependency
Installation
Usage
First create a config file with your database configuration in Application root Folder (IMPORTANT)
-
Example of config file
-
Then Register your composer autoloader
The config class is a singleton (Design pattern) so you can register all config files you want and access to them anywhere in your application.
You can find its documentation here :
Migrations
Migrations are like version control for your database, allowing your team to easily modify and share the application's database schema. Migrations are typically paired with schema builder to easily build your application's database schema. If you have ever had to tell a teammate to manually add a column to their local database schema, you've faced the problem that database migrations solve.
-
How to create migrations
-
Open your terminal and run
- For exampe if I want to create a users table for my application
This command will create a new migration file in the migrations folder that you specified in your config file
If you are familiar with Laravel, this file looks like as laravel migration with some little difference. I have worked with Laravel and I liked the way They make things simple.
up
method is called when you want to create your table anddown
when you want to rollback.Inside
up
method inschema->create
closure you can create all type of column you want . For example we gonna addname
,email
,password
columns in your table- See [Column types]()
- See [Column Definitions]()
-
-
when you're satisfy with yours migrations files, commit them to your database
In your terminal
-
If you want to rollback
In your terminal
This will rollback the latest migrations you've committed
ORM
The package comes also with a little ORM
To retrieve information in our table your use the QueryBuilder class or Query Facade
There are a lot of methods(where
, orWhere
, whereIn
, orWhereIn
, get
, first
, limit
etc...) on table that helps you to retrieve your data
You can find QueryBuilder Documentation here :
You can also create an UserEntity which will represents your User
Then you can fetch users like :
There are plenty methods on QueryBuilder , If you have already work with Laravel Just use it like Laravel QueryBuilder.
All versions of database with dependencies
ext-pdo Version *