Code Monkey home page Code Monkey logo

php_tools's Introduction

updated tools from my old framework

Table of Contents

  1. Updated tools
  2. Configurations
  3. Database class
  4. SQL class
  5. Model class

Updated tools

  • Database class

  • query builder

  • ORM

Configurations

config.php:
$DB_CONN_CONFIG = [
    "host" => "localhost",
    //"port"=>3306,
    "dbname" => "",
    "username" => "",
    "password" => "",
    "charset" => "UTF8"
];

$SQL_DEBUG_MODE = false;

Database class

Database::connect();
//How to work with placeholders:
$a = Database::query('insert into goods (name,price) values ( :nm, :pr)',[':nm'=>'shoes',':pr'=>50],true);print_r($a);
$a = Database::query('insert into goods (name,price) values ( :nm, :pr)',['nm'=>'shoes','pr'=>50],true);print_r($a);
$a = Database::query('insert into goods (name,price) values ( ?, ?)',['shoes',50],true);print_r($a);

$a = Database::query('update goods set price = 100 where id = :id',[':id'=>2],true);print_r($a);
$a = Database::query('select * from goods where id = :id',[':id'=>2],true);print_r($a);
$a = Database::query('delete from goods where id = :id',[':id'=>2],true);print_r($a);

SQL class

$q = SQL::table('goods')->insert(['id'=>20,'name'=>'jeans','price'=>200]);print_r($q);
$q = SQL::table('goods')->insertGetId(['name'=>"adidas",'price'=>120]);print_r( $q);

$q = SQL::table('goods')->where('name = adidas')->update(['price'=>200]);print_r($q);

$q = SQL::table('goods')->where('id > 5')->delete();print_r($q);

$q = SQL::table('goods')->where('price > 30 and price < 300')->get();print_r( $q);
$q = SQL::table('goods')->where('price > 30 and price < 300')->first();print_r( $q);
$q = SQL::table('goods')->where('price > 30 and price < 300')->select('name','price');print_r( $q);

$q = SQL::table('goods')->join('sells','goods.id = sells.id')->get();print_r( $q);

$q = SQL::table('goods')->
    // join('sells','goods.id = sells.id')->
    where("price > 30 and price < 300")->
    orderBy('price','desc')->
    orderBy('name')->
    offset(3)-> 
    limit(2)-> 
    select('name','price');
print_r($q);

Model class

class Product extends Model
{
    protected $table ='goods';
}

$q = Product::find(55);
$q = Product::find([53,54,55]);
$q = Product::all();
$q = Product::where("id = 55")->get();

$q = Product::find(55);
$q->price = 200;
$q->save();

$q->delete();

Product::destroy(51);

$q = Product::create(['price'=>500,'name'=>'nike']);
print_r($q);

php_tools's People

Contributors

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