Giter Site home page Giter Site logo

simpledb's Introduction

SimpleDB

Quick Intro

SimpleDB - a lightweight and easy-to-use wrapper for simple database operations using PDO in PHP.

PDO is useful and portable, but it is often cumbersome and annoying to conduct even the simplest database queries, which requires several lines of code like:

$sth = $db->('SELECT * FROM table WHERE name=:name AND userid=:userid');
$sth->execute(array(':name' => 'bob', ':userid' => 1));
$rows = $sth->fetchAll();

SimpleDB makes basic and common database transactions easy - selecting rows looks like:

$rows = $db->select('table', array('name' => 'bob')); //Gets all rows where name is bob

Quick Start

To start, simply drop the .php file into your directory of choice and require() or include() as desired. Construct a SimpleDB object using the same parameter strings as PDO (except the config strings, leave those out):

$myDB = new SimpleDB('sqlite:databasename.db');

Then you can access the SimpleDB methods directly:

$myDB->select();

Features

  • Parameter binding (to hopefully prevent some forms of SQL injection)
  • Simple one-line queries
  • Utility functions:
    • upsert (insert or update on duplicate) - also supports composite primary keys
    • count rows
    • get single column values

List of methods

For detailed documentation and parameters see the source file Note that all array type parameters below require an associative array where the key corresponds with the column name.

The output for the methods is what you expect it to be (true/false for queries, array of values for select, int for count, etc.).

insert(string $table, array $data)

select(string $table, array $conditions, [string $sortby, boolean $sortdesc])

select_single_row(string $table, array $conditions, [string $sortby, boolean $sortdesc])

select_single_value(string $table, array $conditions, string $column, [string $sortby, boolean $sortdesc])

count(string $table, array $conditions)

update(string $table, array $data, array $conditions)

upsert(string $table, array $data, array $primarykey)

delete(string $table, array $conditions)

simpledb's People

Contributors

kevinpsiu avatar

Stargazers

tablecell avatar Matheus Eduardo Silva Guimarães avatar  avatar Sumith Jitta avatar

Watchers

 avatar

simpledb's Issues

$myDB->insert($table,$data) return true not id

<?php
<?php
require  'simpledb.class.php';
$myDB = new SimpleDB('sqlite:databasename.db');
$schema =<<<S
CREATE TABLE members (
 id integer primary key autoincrement,
  name TEXT,
  age integer ,
  email TEXT 
);
S;
 $myDB->query($schema);
 $id=$myDB->insert('members',['name'=>'test','age'=>100,'email'=>'[email protected]']);
 var_dump($id);

true

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.