2017 © Pedro Peláez
 

library sway-dblayer

Emulates behaviour of SwayDbLayer

image

rev/sway-dblayer

Emulates behaviour of SwayDbLayer

  • Friday, March 17, 2017
  • by Reverze
  • Repository
  • 1 Watchers
  • 0 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

DBLayer

Wrapper for PHP' pdo driver.
This packages comes from swayengine 2., (*1)

Installation

composer require rev/sway-dblayer, (*2)

This will install package at latest version., (*3)

Requirements

This packages requires PDO driver (for default, bundled with PHP)., (*4)

Usage

  • Create connection handler
setDatabaseHostName('localhost');
$dblayerConnector->setDatabaseListenerPort(3306);
$dblayerConnector->setDatabaseName('my_db');
$dblayerConnector->setDatabaseUserName('john_sky');
$dblayerConnector->setUserPassword('my_secret_password');
$dblayerConnector->setSchemaPrefix('dev');
/**
* Sets to 'pdo_mysql'
 */
$dblayerConnector->useMysqlDriver();

/**
* Connects to database and get DBLayer instance
 */
$db = $dblayerConnector->connect();
?>
  • Fetching rows
Run("SELECT * FROM %pr%my_table WHERE type = ?", 
    [ 'eg_type', PDO::PARAM_STR])->assoc();

/**
* Returns first fetched row as associative array
 */
$db->Run("SELECT * FROM %pr%my_table WHERE type = ?",
    [ 'eg_type', PDO::PARAM_STR ])->assoc(0);

/**
* Returns value under column 'column1' at first fetched row.
 */
$db->Run("SELECT column1, column_2 FROM %pr%my_table WHERE type = ?",
    [ 'eg_type', PDO::PARAM_STR ])->assoc(0, 'column1');

/**
* Executes an query and pass array with fetched rows to given anonymous function.
* Anonymous function must returns a value.
 */
$db->Run("SELECT * FROM %pr%my_table WHERE type = ?",
    [ 'eg_type', PDO::PARAM_STR ])->assoc(function($entries) {
        //do something with fetched entries       
        return $entries;
    });
?>
  • Inserting, updating, removing rows
connect();

/**
* Returns True if rows have been updated,
 * returns false if no rows have been updated.
 */
$db->Run("UPDATE %pr%my_table SET column1 = ? WHERE type = ?",
    [ 'value1', PDO::PARAM_STR ],
    [ 'eg_type', PDO::PARAM_STR ])->assoc();

?>

The Versions

17/03 2017

dev-dev

dev-dev

Emulates behaviour of SwayDbLayer

  Sources   Download

GPL-3.0

The Requires

  • php >=7.0

 

by Avatar Reverze

17/03 2017

dev-master

9999999-dev

Emulates behaviour of SwayDbLayer

  Sources   Download

GPL-3.0

The Requires

  • php >=7.0

 

by Avatar Reverze