PHPackages                             godsgood33/php-db - 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. godsgood33/php-db

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

godsgood33/php-db
=================

PHP Database Library

2.6.1(5y ago)078Apache-2.0PHP

Since Dec 27Pushed 5y ago2 watchersCompare

[ Source](https://github.com/godsgood33/php-db)[ Packagist](https://packagist.org/packages/godsgood33/php-db)[ Docs](https://github.com/godsgood33/php-db)[ RSS](/packages/godsgood33-php-db/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (10)Dependencies (2)Versions (20)Used By (0)

PHP DB
======

[](#php-db)

[![Build Status](https://camo.githubusercontent.com/3c0abe8e5158595ef8e8d998110c5f2bef0eff67dd0c1521d09d5ed8ccc263f2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f676f6473676f6f6433332f7068702d64622f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/godsgood33/php-db/build-status/master)[![Code Coverage](https://camo.githubusercontent.com/be29626abd8f079705b7e73a50c9277e2f636fc290f988a62c90a8f85c5e2a3e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f676f6473676f6f6433332f7068702d64622f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/godsgood33/php-db/?branch=master)

This is a library that I have been building to act similar to the WPDB class used for database interactions on Wordpress. I have expanded that library and added things like extended insert, replace, and update syntax building.

Full Documentation
------------------

[](#full-documentation)

Installation
------------

[](#installation)

- ``composer require godsgood33/php_db``

Setup
-----

[](#setup)

- After installation, run `php vendor/godsgood33/php_db/bin/setup.php` to create the required constants to put a required config file:
    - PHP\_DB\_SERVER (IP or hostname of the server you want to connect to)
    - PHP\_DB\_USER (username for the connection)
    - PHP\_DB\_PWD (password for the user)
    - PHP\_DB\_SCHEMA (default schema to connect to, you can use {schema}.{table} syntax if you need to query other tables)
    - PHP\_DB\_LOG\_LEVEL (using PSR/Logger levels, if absent will default to Logger::Error)
    - PHP\_DB\_CLI\_LOG (boolean deciding if you want to show logs on the command line, if absent, will not display)
    - PHP\_DB\_ENCRYPT (boolean to decide if you want to encrypt the password)
    - PHP\_DB\_ENCRYPT\_ALGORITHM (OpenSSL algorithm used to encrypt and decrypt the password)
    - PHP\_DB\_ENCRYPT\_SALT (salt used to encrypt the password)
    - PHP\_DB\_AUTORUN (boolean to decide if you want the SQL command to auto commit and return the results of the query instead of the query itself, FALSE by default).

If you would like to encrypt the password in the configuration file you can run `php vendor/godsgood33/php_db/bin/setup.php --algorithms` to see what encryption algorithms you currently have installed. Once you decide which one you want to use, run `php vendor/godsgood33/php_db/bin/setup.php -a={chosen algorithm}` and it will encrypt the password.

After including autoload, you can create an object as follows

```
$db = new Godsgood33\Php_Db\Database();

```

*OR*

```
$conn = new mysqli("server", "user", "pwd", "schema");
$db = new Godsgood33\Php_Db\Database($conn);

```

Using the second allows you to connect to ANY server that is not the default, however, if the connection DROPs out for any reason, it will **NOT** be reconnected.

We recommend using this class to extend your existing database connection class. Because instantiating will automatically call the parent class constructor and connect to the database using the default values (as long as you don't create your own class constructor, in which case add `parent::__construct()`). Then within your DB class you build the function calls that will perform the queries that you need.

```
class MyDB extends Godsgood33\Php_Db\Database
{
    public function __construct()
    {
        parent::__construct();
    }

    public function getUsers()
    {
        $this->select("users");

        return $this->execute();
    }
}
$db = new MyDB();

```

If you have PHP\_DB\_AUTORUN set to true the above method could be written like the following:

```
public function getUsers()
{
    return $this->select('users');
}

```

Query Type List
---------------

[](#query-type-list)

1. select
    - builds select query
2. selectCount
    - builds select count(1) query
3. insert
    - builds insert query for one (1) row
4. extendedInsert
    - builds insert query with more than one row
5. update
    - builds update query for one row
6. extendedUpdate
    - builds update query for more than one row (requires table to pull from and to update)
7. replace
    - builds replace into query for one row
8. extendedReplace
    - builds replace query for more than one row
9. delete
    - builds delete query (allows for joins and targeted deletion)
10. drop
    - builds drop query (allows for dropping multiple tables)
11. truncate
    - builds truncate query
12. createTable
    - builds create table query (allows for temporary, DDL syntax only, or create from select statement)
13. createTableJson
    - builds a DDL create table query from json (examples/create\_table\_json.json)
14. alterTable
    - builds alter table query (allows for add, modify, and drop column syntax)
15. setVar
    - set a server, system, or connection variable
16. fieldExists
    - queries table to check for presents of a specific field
17. fieldData
    - queries table to get field data
18. tableExists
    - checks for presence of a table
19. fields
    - helper method to build field list
20. parseClause
    - helper method to build where and having clauses
21. flags
    - helper method to parse option flag array
22. groups
    - helper method to build group by syntax
23. order
    - helper method to build order by syntax
24. isConstraint
    - helper method to check for presence of a constraint
25. encrypt / decrypt
    - helper methods to decrypt and encrypt content

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity72

Established project with proven stability

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

Recently: every ~1 days

Total

19

Last Release

1932d ago

Major Versions

1.5 → 2.02019-06-21

PHP version history (2 changes)1.2PHP ^7.2

v1.3PHP ^5.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/80628?v=4)[ryanp](/maintainers/ryanp)[@ryanp](https://github.com/ryanp)

---

Tags

databaselibrarymysqlmysqli

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/godsgood33-php-db/health.svg)

```
[![Health](https://phpackages.com/badges/godsgood33-php-db/health.svg)](https://phpackages.com/packages/godsgood33-php-db)
```

###  Alternatives

[aplus/database

Aplus Framework Database Library

3331.6M7](/packages/aplus-database)[stefangabos/zebra_database

An advanced, compact and lightweight MySQL database wrapper library, built around PHP's MySQLi extension.

11812.0k](/packages/stefangabos-zebra-database)[rah/danpu

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

64401.8k10](/packages/rah-danpu)[go/db

Database library

6624.1k](/packages/go-db)[dabble/dabble

Lightweight wrapper and helpers for MySQLi

1210.4k](/packages/dabble-dabble)

PHPackages © 2026

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