Giter VIP home page Giter VIP logo

database's Introduction

Database PDO Helper

Build Status

PDO Helper implements some common database operations

Installation

Here is composer.json example:

{
    "require": {
        "mac/database": "x"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/mac2000/database"
        }
    ]
}

Usage example

First of all you need some database connection:

$db = new Database(new PDO('mysql:host=localhost;dbname=example', 'root', 'root'));
// or for test purposes
$db = new Database(new PDO('sqlite::memory:'));

Retrieve all/one row(s):

$users = $db->all("SELECT * FROM users");
$user = $db->one("SELECT * FROM users WHERE user_id = :user_id", array('user_id' => 1));

Retrieve computed value:

$count = $db->cell("SELECT COUNT(*) FROM users");

Modify data:

$lastInsertId = $db->execute(
    "INSERT INTO users (first_name, last_name, age) VALUES(:first_name, :last_name, :age)",
    array('first_name' => 'Hello', 'last_name' => 'World', 'age' => 9)
);

$rowsAffectedCount = $db->execute(
    "DELETE FROM users WHERE user_id = :user_id",
    array('user_id' => 2)
);

Run tests

Look at .travis.yml there is few tests that are runned:

vendor/bin/phpunit
vendor/bin/phpcpd src tests
vendor/bin/phpmd src,tests text cleancode, codesize, controversial, design, naming, unusedcode
vendor/bin/phpcs --standard=psr2 src tests

database's People

Contributors

mac2000 avatar

Watchers

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