PHPackages                             saturn/database - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. saturn/database

ActiveLibrary[Database &amp; ORM](/categories/database)

saturn/database
===============

PHP PDO wrapper class.

1.3.0(10y ago)0331GPL-2.0PHP

Since Dec 30Pushed 10y ago1 watchersCompare

[ Source](https://github.com/pkrll/Database)[ Packagist](https://packagist.org/packages/saturn/database)[ Docs](https://github.com/pkrll/Database)[ RSS](/packages/saturn-database/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (4)DependenciesVersions (5)Used By (1)

Database [![Latest Stable Version](https://camo.githubusercontent.com/d192e9a6ae4c3001ccaa8ae68bc1878993ac3d0d19d11bb638f00b740c9c7815/68747470733a2f2f706f7365722e707567782e6f72672f73617475726e2f64617461626173652f762f737461626c65)](https://packagist.org/packages/saturn/database) [![License](https://camo.githubusercontent.com/6617adc833b010c96ce37ad58e244ef35ac72699e64b883885cb675f61d2dfc6/68747470733a2f2f706f7365722e707567782e6f72672f73617475726e2f64617461626173652f6c6963656e7365)](https://packagist.org/packages/saturn/database)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#database--)

A PDO Wrapper Class.

### Installation

[](#installation)

##### With Composer (recommended):

[](#with-composer-recommended)

```
$ composer require saturn/database
```

#### Setup

[](#setup)

Define and set the following constants:

```
define("kHostname", "hostname"); // The hostname on which the database server resides.
define("kDatabase", "database"); // The name of the database.
define("kUsername", "username"); // The username.
define("kPassword", "password"); // The password.
```

### Usage

[](#usage)

Using Database is easy. Just include it (either manually or using Composer's loader), and create an instance by supplying the above constants. See [below](#examples) for more examples.

```
use saturn\database\Database;

$database = new Database($hostname, $database, $username, $password);

// Retrieve from the database
$SQLQuery = "SELECT SomeColumn FROM SomeTable";
$response = $database->read($SQLQuery);

// Insert into the database
$SQLQuery = "INSERT INTO SomeTable (SomeColumn) VALUES (:someValue)";
$SQLParam = array("someValue" => "Foobar");
$response = $database->write($SQLQuery, $SQLParam);
```

### API

[](#api)

Below outlines the public methods of the Database class.

```
/*
 *  Create the PDO instance and set the defaults attributes on the database handle.
 *
 *  @param      string  Database hostname.
 *  @param      string  Database name.
 *  @param      string  Username.
 *  @param      string  Password.
 */
public function __construct($hostname, $database, $username, $password) {}

/**
 *  Run the supplied query. Only for fetching rows from
 *  the database.
 *
 *  @param      string  Optional. The SQL query to execute.
 *  @param      array   Optional. Additional parameters to supply to the query.
 *  @param      bool    If true, fetches all matching rows. Defaults to TRUE.
 *  @return     array
 **/
public function read($query, $params = NULL, $shouldFetchAll = true) {}

/**
 *  Run the supplied query. Only for adding rows to the the database.
 *
 *  @param      string  Optional. The SQL query to execute.
 *  @param      array   Optional. Additional parameters to supply to the query.
 *  @return     array
 **/
public function write($query = NULL, $params = NULL) {}

/**
 *  Return an array of error information about the last performed operation.
 *
 *  @param      bool    Value determines if the errorInfo should be performed on the
 *                      database handle or the statement handle.
 *  @return     array
 */
public function error($connection = true) {}

/**
 *  Execute the prepared SQL statement.
 *
 *  @param      array   Optional. The input parameters.
 *  @return     mixed
 */
public function execute($params = NULL) {}

/**
 *  Fetch all the rows in the result set.
 *
 *  @param      int     Optional. Value controls how the row should be returned. The value
 *                      must be one of the FETCH_* constants. Defaults to: FETCH_ASSOC.
 *  @return     mixed
 */
public function fetchAll($flags = PDO::FETCH_ASSOC) {}

/**
 *  Fetch the next row in the result set.
 *
 *  @param      int     Optional. Value controls how the row should be returned. The value
 *                      must be one of the FETCH_* constants. Defaults to: FETCH_ASSOC.
 *  @return     mixed
 */
public function fetch($flags = PDO::FETCH_ASSOC) {}

/**
 * Prepares a statement for execution.
 *
 *  @param      string  The SQL string.
 *  @return     bool
 */
public function prepare($query) {}

/**
 * Bind a value to a named or question mark placeholder
 * in the prepared SQL statement.
 *
 *  @param      mixed   The parameter identifier. For named placeholder, this value must be a
 *                      string (:name). For a question mark placeholder, the value must be the
 *                      1-indexed position of the parameter.
 *  @param      mixed   The value to bind to the parameter.
 *  @param      int     Data type for the parameter, using the predefined PDO constants:
 *                      http://php.net/manual/en/pdo.constants.php
 *  @return     bool
 */
public function bindValue($param, $value, $dataType) {}

/**
 *  Bind a referenced variable to a named or question mark
 *  placeholder in the prepared SQL statement.
 *
 *  @param      mixed   The parameter identifier. For named placeholder, this value must be a
 *                      string (:name). For a question mark placeholder, the value must be the
 *                      1-indexed position of the parameter.
 *  @param      mixed   Variable to bind to the parameter.
 *  @param      int     Data type for the parameter, using the predefined PDO constants:
 *                      http://php.net/manual/en/pdo.constants.php
 *  @return     bool
 */
public function bindParam($param, &$variable, $dataType) {}

/**
 *  Number of rows affected by last operation.
 *
 *  @return     int
 */
public function rowCount() {}

/**
 *  Return the id of last inserted row.
 *
 *  @return     int
 */
public function lastInsertId() {}
```

### Examples

[](#examples)

Retrieving from the database:

```
// Prepare the query
$database->prepare("SELECT SomeColumn FROM SomeTable");

// Call the shorthand method read() to fetch the results
$response = $database->read();

// Because the read/write methods prepares the statement, the above code can be shortened:
$response = $database->read("SELECT SomeColumn FROM SomeTable");

// Retrieve a specific row like this:
$response = $database->read("SELECT SomeColumn FROM SomeTable WHERE id = :id", array("id" => $id));
```

Adding to the database:

```
$values = array(
  "ThisValue"  => "Foo!",
  "ThatValue"  => "Bar!"
);

$SQLQuery = "INSERT INTO SomeTable (someColumn, anotherOne) VALUES (:ThisValue, :ThatValue)";
$database->prepare($SQLQuery);

// Bind the values that are to be inserted
$database->bindValue(":ThisValue", $values["ThisValue"]);
$database->bindValue(":ThatValue", $values["ThatValue"]);

$response = $this->write();
```

Deleting from the database:

```
$SQLQuery = "DELETE FROM SomeTable WHERE id = :id";
$SQLParam = array("id" => $id);
$response = $database->write($SQLQuery, $SQLParam);
```

A bit more complicated example:

```
$values = array(
  array(
    "ThisValue"  => "Foo 123",
    "ThatValue"  => "Bar 456"
  ),
  array(
    "ThisValue"  => "Foo 789",
    "ThatValue"  => "Bar 012"
  ),
  array(
    "ThisValue"  => "Foo 345",
    "ThatValue"  => "Bar 678"
  )

// Create the unnamed placeholders, based on the number of values the row will take:
$markers = array_fill(0, count($values[0]), '?');
$markers = '(' . implode(", ", $markers) . ')';

// The number of placeholders must match the number of values that are to be inserted
// in the VALUES-clause. Create the array with array_fill() and join the array with
// the query-string.
$clause = array_fill(0, count($values), $markers);
$query  = "INSERT INTO SomeTable (someColumn, anotherOne) VALUES " . implode(", ", $clause);
$database->prepare($query);

// Bind the values using bindValue(). Using question marked placeholders, the value
// must be 1-indexed, that is starting at position 1.
$index = 1;
foreach ($values AS $key => $value) {
  $this->bindValue($index++, $value['ThisValue']);
  $this->bindValue($index++, $value['ThatValue']);
}

// A more pretty and dynamic way to write the above statement could be by going
// by the columns of the array, like so:
$columns = array_keys($values[0]);
foreach ($values AS $key => $value) {
  foreach ($columns AS $column)
    $this->bindValue($position++, $value[$column]);
  }
}

// And don't forget to write to database
$response = $database->write();
```

### Author

[](#author)

Database was written by Ardalan Samimi.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~11 days

Total

4

Last Release

3793d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/140205?v=4)[Ardalan Samimi](/maintainers/pkrll)[@pkrll](https://github.com/pkrll)

---

Top Contributors

[![pkrll](https://avatars.githubusercontent.com/u/140205?v=4)](https://github.com/pkrll "pkrll (9 commits)")

---

Tags

databasemysqlpdo

### Embed Badge

![Health badge](/badges/saturn-database/health.svg)

```
[![Health](https://phpackages.com/badges/saturn-database/health.svg)](https://phpackages.com/packages/saturn-database)
```

###  Alternatives

[lincanbin/php-pdo-mysql-class

A PHP MySQL PDO class similar to the Python MySQLdb, which supports iterator and parameter binding when using 'WHERE IN' statement.

2376.6k](/packages/lincanbin-php-pdo-mysql-class)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
