soupmix/sql

This package is abandoned and no longer maintained. No replacement package was suggested.

Simple SQL abstraction layer adapter to handle CRUD operations.

0.8.1 2017-07-23 16:09 UTC

This package is auto-updated.

Last update: 2021-06-26 15:24:56 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality Code Coverage

Simple SQL abstraction layer adapter to handle CRUD operations written in PHP and built on top of Doctrine/DBAL. This library does not provide any ORM or ODM.

Installation

It's recommended that you use Composer to install Soupmix.

$ composer require soupmix/sql "~0.7"

This will install Soupmix and all required dependencies. Soupmix requires PHP 5.6.0 or newer.

Documentation

API Documentation: See details about the db adapters functions:

Usage

// Connect to SQL Service


$config = [
    'dbname'    => 'test',
    'user'      => 'root',
    'password'  => '',
    'host'      => '127.0.0.1',
    'port'      => 3306,
    'charset'   => 'utf8',
    'driver'    => 'pdo_mysql',
];
$client = \Doctrine\DBAL\DriverManager::getConnection($config);
$sql = new \Soupmix\SQL(['db_name'=>$config['dbname']], $client);


$docs = [];
$docs[] = [
    "full_name" => "John Doe",
    "age" => 33,
    "email"    => "johndoe@domain.com"      
];
$docs[] = [
    "full_name" => "Jack Doe",
    "age" => 38,
    "email"    => "jackdoe@domain.com"
];

$docs[] = [
    "full_name" => "Jane Doe",
    "age" => 29,
    "email"    => "janedoe@domain.com"
];

foreach($docs as $doc){
    // insert user into database
    $sql_user_id = $sql->insert("users",$doc);
}
// get user data using id
$user_data = $sql->get('users', $sql_user_id);



// user's age lower_than_and_equal to 34 or greater_than_and_equal 36 but not 38
$filter = [[['age__lte'=>34],['age__gte'=>36]],"age__not"=>38];

//find users that has criteria encoded in $filter
$docs = $sql->find("users", $filter);


Contribute

  • Open issue if found bugs or sent pull request.
  • Feel free to ask if you have any questions.