Code Monkey home page Code Monkey logo

php-orm's Introduction

PHP ORM library

=============================

The open source ORM library on PHP.

Introduction

The PHP-ORM follows ActiveRecord architectural pattern.

More details can be found here.

Minimum Requirements

  • PHP 5.4+
  • PDO driver for your respective database

Supported Databases

  • MySQL
  • PostgreSQL

Features

  • Finder methods
  • Writer methods
  • Relationships
  • Validations
  • Callbacks
  • Transactions
  • Support for multiple adapters
  • Table's schema

Installation

Use composer to install PHP ORM library. Just add to your composer.json a text below and run the php composer.phar update command to install it:

{
    "require": {
        "gigorok/php-orm": "0.2.*"
    }
}

Basic CRUD

Retrieve

These are your basic methods to find and retrieve records from your database.

$post = Post::find(1);
echo $post->title; # 'Test title!'
echo $post->author_id; # 5

# also the same since it is the first record in the db
$post = Post::first();

# finding using a conditions array
$posts = Post::where('name=? or id > ?', array('The Bridge Builder', 100));

Create

Here we create a new post by instantiating a new object and then invoking the save() method.

$post = new Post();
$post->title = 'My first blog post!!';
$post->author_id = 5;
$post->save();
# INSERT INTO `posts` (title,author_id) VALUES('My first blog post!!', 5)

Update

To update you would just need to find a record first and then change one of its attributes.

$post = Post::find(1);
echo $post->title; # 'My first blog post!!'
$post->title = 'Some real title';
$post->save();
# UPDATE `posts` SET title='Some real title' WHERE id=1

$post->title = 'New real title';
$post->author_id = 1;
$post->save();
# UPDATE `posts` SET title='New real title', author_id=1 WHERE id=1

Destroy

Deleting a record will not destroy the object. This means that it will call sql to delete the record in your database but you can still use the object if you need to.

$post = Post::find(1);
$post->destroy();
# DELETE FROM `posts` WHERE id=1
echo $post->title; # 'New real title'

License

Licensed under the MIT license.

php-orm's People

Contributors

bitdeli-chef avatar gigorok avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.