Code Monkey home page Code Monkey logo

simple-db-framework's Introduction

Simple DB Operation Framework with PHP

Configuration

Config file : Irfa/config/database.php

<?php
$config = [
    'DB_host' => 'localhost',
    'DB_name' => 'database_name',
    'DB_username' => 'yourusername',
    'DB_password' => 'yourpassword',
    'DB_port' => '3306',
    'DB_driver' => 'mysql',
   ];

Basic Usage

Fetch all rows

  <?php
    require 'Autoloader.php';
    use Irfa\DBOperation as DB;
    
    $res = DB::table('book')->get();
     foreach ($res as $r):
        echo $r['title']."<br>";
      endforeach;

Fetch Single row

  $data= DB::table('book')
    	->where(['book_id' => 'ABC123'])
    	->first();
    	
    	echo $data['title'];

Select specific column

  $data= DB::table('book')
        ->select(['book_id','title','synopsis'])
    	->where(['book_id' => 'ABC123'])
    	->first();
    	
    	echo $r['book_id'].' '.$data['title'].' '.$r['author'];

Order by

$res = DB::table('book')->orderBy('author','DESC')->get();
         foreach ($res as $r):
            echo $r['title']."<br>";
          endforeach;

Insert Data

  $params = ['title'=>'Lorem', 'author' => 'Ipsum'];
  DB::table('book')->insert($params);

Update data

$params = ['title'=>'Ipsum', 'author' => 'Lorem'];
DB::table('book')
->where(['book_id' => 'ABC123'])
->update($params);

Delete data

DB::table('book')
	->where(['book_id' => 'ABC123'])
	->delete();

simple-db-framework's People

Contributors

irfaardy avatar

Stargazers

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