Code Monkey home page Code Monkey logo

php-pdo's Introduction

How to use it

Files:

  • config.php // file with settings of DB
  • DB.php // class of DB
  • index.php // examples

How to work

First of all you should to initialize class. For exemple like this:

$DB = new DB(require 'config.php');

File config.php should be an associative array:

return [
    'connection' => 'mysql:host=127.0.0.1',
    'name' => 'test1',
    'username' => 'root',
    'password' => '',
    'options' => [
        PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
    ]
];

Now you can work with Class.

To SELECT something from DB you should refer to $DB->select().

There are parameters of select('@param1','@param2','@param3','@param4','@param5'):

  • @param1 // Table in DB where to Select
  • @param2 // What to Select (For example: 'test_id,test_text', or you can write '*' to Select all columns).
  • @param3 // Some conditions (OPTIONAL)
  • @param4 // How to order (OPTIONAL)
  • @param5 // Limits (OPTIONAL)

To INSERT something in DB you should refer to $DB->insert().

There are parameters of insert('@param1','@param2'):

  • @param1 // Table in DB where to Insert
  • @param2 // What to Insert

Use it like this:

$DB->insert( 'Table_Where_To_Insert',
    [
        'Name_Of_Column1' => $param1,
        'Name_Of_Column2' => $param2,
        'Name_Of_Column3' => $param3,
    ]
);

To UPDATE something in DB you should refer to $DB->update().

There are parameters of update('@param1','@param2','@param3'):

  • @param1 // Table in DB where to Insert
  • @param2 // What to Insert
  • @param3 // Some conditions

Use it like this:

$DB->update( 'Table_Where_To_Update',
    [
        'Name_Of_Column1' => $param1,
        'Name_Of_Column2' => $param2,
        'Name_Of_Column3' => $param3,
    ],
    [
        'Name_Of_Column_With_Condition1' => $condition1,
        'Name_Of_Column_With_Condition2' => $condition2
    ]
);

To DELETE something in DB you should refer to $DB->delete().

There are parameters of delete('@param1','@param2'):

  • @param1 // Table in DB where to Delete
  • @param2 // What to Delete

Use it like this:

$DB->delete( 'Table_Where_To_Delete',
    [
        'Name_Of_Column_With_Condition1' => $condition1,
        'Name_Of_Column_With_Condition2' => $condition2
    ]
);

php-pdo's People

Contributors

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