PHPackages                             gorgo/golibdatabase - 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. gorgo/golibdatabase

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

gorgo/golibdatabase
===================

Database layer

0.2.1(5y ago)0325MITPHPPHP 8.\*

Since Oct 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/swaros/golib-database)[ Packagist](https://packagist.org/packages/gorgo/golibdatabase)[ Docs](https://github.com/swaros/golib-database)[ RSS](/packages/gorgo-golibdatabase/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

golib-database
==============

[](#golib-database)

golib database layer

### install

[](#install)

composer `composer require gorgo/golibdatabase`

### basic usage

[](#basic-usage)

connect to a mysql Database

```
use golibdatabase\Database\MySql;
$connect = new MySql\ConnectInfo( 'username','password','hostname','default_shema' );
$db = new MySql( $connect );
$result = $db->select( 'SELECT * FROM Tablename' );
if ($result->getErrorNr()) {
        echo " --- mysql error:" . $result->getError();
    } else {
        echo " --- got " . $result->count() . 'entries ';
        var_dump( $result->getResult() );
    }
}
```

### Connection Manager

[](#connection-manager)

is written for cases you can not be sure the connection is already existing (for example by replacing a singelton db implementation)

```
// run the whole code 3 times just to explain what the connection-manager is doing
for ($i = 0; $i < 3; $i++) {
    $connect = new MySql\ConnectInfo( 'username','password','hostname','default_shema' );

    $connectManager = new Database\ConnectManager();

    if ($connectManager->connectionIsStored( $connect )) {
        $db = $connectManager->getStoredConnection( $connect );
        echo ' --- use existing connection --- ';
    } else {
        echo ' ---- create a new connection --- ';
        $db = new MySql( $connect );
        $connectManager->registerConnection( $db );
    }

    $result = $db->select( 'SELECT * FROM Tablename' );

    if ($result->getErrorNr()) {
        echo " --- mysql error:" . $result->getError();

    } else {
        echo " --- got " . $result->count() . 'entries ';
        var_dump( $result->getResult() );

    }
}
```

### Table Example

[](#table-example)

Explain by example.

Table Structure and Content.

```
CREATE TABLE `golib-db` (
`primId` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`Content` VARCHAR( 250 ) NOT NULL ,
`DateExample` DATETIME NOT NULL ,
`ExampleValue` MEDIUMINT NOT NULL
) ENGINE = InnoDB;

INSERT INTO `golib-db` (
`primId` ,
`Content` ,
`DateExample` ,
`ExampleValue`
)
VALUES (
NULL , 'test content', '2017-09-30 00:00:00', '450'
), (
NULL , 'second content', '2017-09-19 00:00:00', '9887'
);
```

step 1: Build a Propertie Class that reflects the structure of the database. this class have to extend from `golib\Types\PropsFactory`

Like so:

```
/**
 * the property Class descriptes the expected fields
 */
use golib\Types;
/**
 * the property Class descriptes the expected fields
 */
class exampleProp extends Types\PropsFactory {
    /**
     * autoinc, primary
     * @var int
     */
    public $primId = NULL;
    /**
     *
     * @var string
     */
    public $Content = '';

    /**
     * a date example
     * @var Types\Timer
     */
    public $DateExample = Types\MapConst::TIMER;
    /**
     * just a integer
     * @var int
     */
    public $ExampleValue = 0;

}
```

Step 2: Define the Table Class that points to the table, and setup the Propertie Class and the Tablename.

```
use golib\Types;
/**
 * the table class
 * that maps to the table in the database.
 *
 * they need to know about the structure by using
 * the property class
 *
 * and (of course) the table name
 */
class exampleTable extends MySql\Table {
    /**
     * defines the content.
     * how the rows looks like
     * @return \exampleProp
     */
    public function getPropFactory () {
        return new exampleProp( 'primId' );
    }
    /**
     * just the tablename
     * @return string
     */
    public function getTableName () {
        return 'golib-db';
    }

}
```

That is all what is needed to setup the basic Model for a Table. to read from this this table you make a new instance of these class and fetch the Data by using a existing Database Connection.

```
// initiate the modell of the table
$golibTable = new exampleTable();

// get the content by using a existing database connection
$golibTable->fetchData( $db );

// one way to iterate the content.
$golibTable->foreachCall( function(exampleProp $row) {
    var_dump( $row );
} );
```

Now we have a Modell of the Database Table as an PHP-Object this will read the full content of the Table and assign it to row-objects.

#### WhereSet

[](#whereset)

But mostly you don't need the whole Content. in MySQL you handle this by adding a `where` statement to filter the result. The same can be done by using a `WhereSet`.

so change the code in the example

```
$where = new MySql\WhereSet();
$where->isEqual( 'ExampleValue', 9887 );

$golibTable = new exampleTable( $where );
```

now we will got the matching values only.

#### Limit

[](#limit)

The `Limit` class is usefull to Limit the Amount of entries like the regular Limit from MySQL. A instance of Limit have to be the second Parameter.

```
$Limit = new MySql\Limit();
$Limit->count = 1;

$golibTable = new exampleTable( NULL, $limit );
```

this object have just to Properties. `start` defines the offset and `count` the count of entries.

```
$Limit = new MySql\Limit();

$Limit->count = 1;
$Limit->start = 1; // equal to LIMIT 1,1

$Limit->count = 100;
$Limit->start = 0; // equal to LIMIT 0,100
```

#### Order

[](#order)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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 ~599 days

Total

3

Last Release

1946d ago

PHP version history (2 changes)0.1.2PHP &gt;=5.3.0

0.2.0PHP 8.\*

### Community

Maintainers

![](https://www.gravatar.com/avatar/d9732e90d3a9e014c98031f18bf65262cd185f5a8dd0ce910420e249c3799846?d=identicon)[gorgo](/maintainers/gorgo)

---

Top Contributors

[![swaros](https://avatars.githubusercontent.com/u/5437750?v=4)](https://github.com/swaros "swaros (18 commits)")

---

Tags

databasemysql

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gorgo-golibdatabase/health.svg)

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

###  Alternatives

[rah/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

64401.8k10](/packages/rah-danpu)

PHPackages © 2026

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