Git Product home page Git Product logo

fdo's Introduction

FDO

FDO - Fast DB ORM

FDO is a PHP based library to assist user to do DB create/edit/delete/search/find with simply function without creates SQL manually. It's uses ORM method to execute data from / to DB.

  • Easy to use
  • Fast to build DB operate and query to save coding time
  • OOP / ORM method
  • Compatitable with Laravel
  • Allows connect mutiple DB at the same time
  • Easier debug ( just call a build-in method -- debug(). e.g: $this->users()->where("user_id", 1)->debug()->get() )

Note

If you encountered when installing -- "Class 'fdom' not found" (Illuminate\Foundation\AliasLoader::load("honwei189\FDO\FDOM")), please execute following command:

composer dump && php artisan optimize

Example

<?php
require __DIR__ . '/../vendor/autoload.php';

honwei189\Flayer\Config::load();
$app = new honwei189\Flayer;
$app->bind("honwei189\\FDO");

$dbh = $app->FDO()->connect(honwei189\Flayer\Config::get("database", "mysql"));

foreach ($app->FDO()->q('SELECT * from users') as $row) {
    print_r($row);
}

## Insert data
$insert = $app->FDO()->from("users");
$insert->name = "AAA";
$insert->email = "aaa@example";
$insert->gender = "M";
echo $insert->store(); // or you can use $insert->save();

## Altenative way to insert...

foreach($app->FDO()->_post as $k => $v) { // or $insert->_post
    $insert->$k = $v;
}

$insert->soft_update(false); // true = Dry run only
$insert->store();


## Update data
$update = $app->FDO()->from("users");
$update->name = "A.AA";
$update->update($insert->_id); // or you can use $update->save($this->_id);

# Delete data
$delete = $app->FDO()->from("users");
$delete->by_id($insert->_id)->delete(); // or you can use $delete->delete("id = ". $insert->_id);  or you can use $delete->where("id", $insert->_id)->delete();

## Retrieve data from DB
$users = $app->FDO()->from("users"); // Get data from table -- users
$users->debug(false); // false = disable debug mode.  stop printing SQL
print_r($users->where("userid='admin'")->get("id, userid, name"));

var_dump($app::FDO()->is_connected());
var_dump(honwei189\Flayer\Core::FDO()->is_connected());


var_dump($app->FDO()->is_connected());
foreach ($dbh->query('SELECT * from users') as $row) {
    print_r($row);
}

var_dump(honwei189\Flayer\Container::get("FDO")->is_connected());

$app->FDO()->fetch_mode(\PDO::FETCH_INTO);

$app->FDO()->set_table("users"); // Get data from table -- users
print_r($app->FDO()->where("userid='admin'")->get("id, userid, name"));
print_r($app->FDO()->users()->get("id, userid, name"));

class aaa
{
    public $id;
    public $m_name;
}

 
print_r($app->FDO()->users()->fetch_mode()->limit(20)->find());  // Get data from table -- users  with default fetch mode -- PDO::FETCH_LAZY

$list = $app->FDO()->history_logs(); // Get data from table -- history_logs
print_r($list->fetch_mode(\PDO::FETCH_INTO, new aaa)->limit(20)->order_by("id", "desc")->find("id, m_name"));
print_r($list->limit(20)->order_by("id", "desc")->cols("id, m_name")->find());
print_r($list->limit(20)->order_by("id", "desc")->cols(["id", "m_name"])->find());

Installation

To use FDO, you are requires to install Flayer

$ composer require honwei189/fdo

or

$ git clone https://github.com/honwei189/flayer.git
$ git clone https://github.com/honwei189/fdo.git

Documentation

Coming soon...

fdo's People

Contributors

honwei189 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.