2017 © Pedro Peláez
 

library rdbms

RDBMS support for the XP Framework

image

xp-framework/rdbms

RDBMS support for the XP Framework

  • Sunday, July 15, 2018
  • by thekid
  • Repository
  • 6 Watchers
  • 1 Stars
  • 40,112 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 69 Versions
  • 9 % Grown

The README.md

RDBMS support for the XP Framework

Build status on GitHub Build status on AppVeyor XP Framework Module BSD Licence Requires PHP 7.0+ Supports PHP 8.0+ Latest Stable Version, (*1)

RDBMS access APIs, connection manager, reverse engineering, O/R mapping., (*2)

The DriverManager model

To retrieve a connection class from the driver manager, you need to use the rdbms.DriverManager class., (*3)

use rdbms\DriverManager;

$conn= DriverManager::getConnection('sybase://user:pass@server/NICOTINE');

The DriverManager class expects a unified connection string (we call it DSN)., (*4)

Supported drivers

The DriverManager will select an appropriate driver from the DSN string via its name. This will load an implemenation class which is either based on a PHP extension or implements the protocol to communicate with the database system in userland code. For the latter case, you need not do anything to your PHP setup; if there's a hard dependency on a PHP extension, you need to install that before you can use the driver., (*5)

Database system DSN name PHP Extensions Userland driver
MySQL mysql ext/mysql or ext/mysqli :white_check_mark:
PostgreSQL pgsql ext/pgsql
SQLite3 sqlite ext/sqlite3
Interbase/FireBird ibase ext/interbase
Sybase sybase ext/sybase-ct :white_check_mark:
MSSQL mssql ext/mssql or ext/sqlsrv :white_check_mark:

Basics

Once we have fetched a specific database connection class, we can now invoke a number of methods on it., (*6)

Selecting

Selecting can be done with the "one-stop" method select() which will return all results into an array. Alternatively, the query() method allows iterative fetching., (*7)

$news= $conn->select('news_id, caption, author_id from news');
// $news= [
//   [
//     'news_id'   => 12,
//     'caption'   => 'Hello World',
//     'author_id' => 1549
//   ]
// ]

$q= $conn->query('select news_id, caption, author_id from news');
while ($record= $q->next()) {
  // $record= [
  //   'news_id'   => 12,
  //   'caption'   => 'Hello World',
  //   'author_id' => 1549
  // ]
}

Inserting

To "bind" parameters to an SQL query, the query, select, update, delete and insert methods offer a printf style tokenizer and support varargs syntax. These take care of NULL, type handling and proper escaping for you., (*8)

$conn->insert('
  into news (
    caption, author_id, body, extended, created_at
  ) values (
    %s, -- caption
    %d, -- author_id
    %s, -- body
    %s, -- extended
    %s  -- created_at
  )',
  $caption,
  $authorId,
  $body,
  $extended,
  Date::now()
);

Updating

The update() and delete() methods will return the number of affected rows, in case you're interested., (*9)

$conn->update('news set author_id= %d where author_id is null', $authorId);

Deleting

Even if your RDBMS requires you to use single quotes (or what-else), the API will take care of rewriting string literals for you., (*10)

$conn->delete('from news where caption = "[DELETE]"');

Exceptions

All of the above methods will throw exceptions for failed SQL queries, syntax errors, connection failure etc. All these exceptions are subclasses of rdbms.SQLException, so to catch all possible errors, use it in the catch clause:, (*11)

+ rdbms.SQLException
|-- rdbms.ConnectionNotRegisteredException
|-- rdbms.SQLConnectException
|-- rdbms.SQLStateException
`-- rdbms.SQLStatementFailedException
    |-- rdbms.SQLConnectionClosedException
    `-- rdbms.SQLDeadlockException

Transactions

To start a transaction, you can use the connection's begin(), commit() and rollback() methods as follows:, (*12)

public function createAuthor(...) {
  $tran= $conn->begin(new Transaction('create_author'));

  try {
    $id= $conn->insert('into author ...');
    $conn->insert('into notify ...');

    $tran->commit();
    return $id;
  } catch (SQLException $e) {
    $tran->rollback();
    throw $e;
  }
}

Note: Not all database systems support transactions, and of those that do, not all support nested transactions. Be sure to read the manual pages of the RDBMS you are accessing., (*13)

The Versions

15/07 2018

dev-refactor/remove-deprecated-classes

dev-refactor/remove-deprecated-classes http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

15/07 2018

dev-refactor/remove-affectedrows

dev-refactor/remove-affectedrows http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

15/07 2018

dev-feature/reconnect-by-default

dev-feature/reconnect-by-default http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

30/05 2018
13/03 2017

8.0.0.x-dev

8.0.0.9999999-dev http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

13/03 2017
13/03 2017

7.0.0.x-dev

7.0.0.9999999-dev http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

13/03 2017
15/12 2016
23/07 2016
04/07 2016
24/06 2016
05/06 2016
04/06 2016
07/05 2016
02/05 2016
22/04 2016

dev-feature/postgres-dbadapter-fixes

dev-feature/postgres-dbadapter-fixes http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

18/04 2016
29/03 2016

dev-fix/free-result

dev-fix/free-result http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

21/02 2016
21/02 2016

v7.0.1

7.0.1.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

21/02 2016
21/02 2016
21/02 2016

dev-infrastructure/appveyor

dev-infrastructure/appveyor http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

20/02 2016
20/02 2016
24/01 2016
24/01 2016
09/01 2016
09/01 2016
20/12 2015
20/12 2015

dev-rfc/avoid-ensure

dev-rfc/avoid-ensure http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

20/12 2015
09/12 2015

v6.4.4

6.4.4.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

30/11 2015

v6.4.3

6.4.3.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

26/09 2015

v6.4.2

6.4.2.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

25/09 2015

v6.4.1

6.4.1.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

12/07 2015

v6.4.0

6.4.0.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

24/06 2015

v6.3.2

6.3.2.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

13/06 2015

v6.3.1

6.3.1.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

02/06 2015

v6.3.0

6.3.0.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

01/06 2015

v6.2.2

6.2.2.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

22/05 2015

v6.2.1

6.2.1.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

21/05 2015

v6.2.0

6.2.0.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

12/02 2015

v6.1.1

6.1.1.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

06/02 2015

v6.1.0

6.1.0.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

06/02 2015

dev-fix/sybase-unicode

dev-fix/sybase-unicode http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

10/01 2015

v6.0.0

6.0.0.0 http://xp-framework.net/

RDBMS support for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp