PHPackages                             hypnokizer/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. hypnokizer/database

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

hypnokizer/database
===================

Class to execute queries using PDO and SQLite3

v7.0.0(1mo ago)041MITPHPPHP &gt;=8.3.0

Since Jun 4Pushed 1mo agoCompare

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

READMEChangelogDependenciesVersions (2)Used By (1)

Database class
==============

[](#database-class)

This class exists to quickly and easily execute perpared queries using the PDO wrapper for an SQLite3 database.

Basic Use
---------

[](#basic-use)

Instantiate the object. If the database file does not exist, it will be created. It should have an extension of `*.db`. The directory and the file itself should be fully writeable.

The only parameter is an array containing database credentials. The default values are variables defined in an include file, but you can overwrite them for each instance. A try/catch block is used to set up the connection and will throw an error if the database cannot connect.

```
define('DBPATH', '../app/database/');
define('DB', 'chinook.db');

$attr = array(
    'dbpath' => DBPATH,
    'db' => DB
);

$db = new db($attr);

```

The `run()` method is the main method used. It executes the query and stores the values within class properties which can be accessed by the user.

### Simple Query

[](#simple-query)

There are (2) parameters. The first, and only required, parameter is the query. Simple queries can be executed like this:

```
$query = 'SELECT * FROM thetable ORDER BY id';

$db->run($query);

```

### Prepared Statement

[](#prepared-statement)

To include user input, prepared statements are required. The `params` variable contains the data to bind to the `?` placeholders.

```
$query = 'SELECT * FROM thetable WHERE id = ? OR name = ?';

$data = array(3, 'Nathan');

$db->run($query, $data);

```

#### Results

[](#results)

The results from `SELECT` queries are stored in a multidimensional array called `results`. Each record is an associative array. This can be accessed with a `foreach()` loop.

```
foreach($db->results as $row) {
    echo $row['fieldname'];
}

```

Depending upon the type of query executed, there are several values stored in class properties:

PropertyDescription`lastID`The last ID assigned to an insert query`naffected`The number of rows affected by a query`nrows`The number of rows returned by a query`status`Boolean value showing if the query was successful or notCreating a CSV File
-------------------

[](#creating-a-csv-file)

There is also a method to create a CSV file from the record set. To do this, you must first execute the query by calling the `run()` method. Rather than step through the results array, you have the option of calling the `createCSV()` method.

The method takes one parameter, which is a filename, including extension.

```
$db->run($query, $data);

$db->createCSV('myfilename.csv');

```

Debugging
---------

[](#debugging)

There are two methods used for debugging. The `showResults()` method shows a summary array for the query. The `showObject()` method shows the entire PDO object. These methods can be called at any point in the script.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance90

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

50d ago

### Community

Maintainers

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

---

Top Contributors

[![Hypnokizer](https://avatars.githubusercontent.com/u/279126957?v=4)](https://github.com/Hypnokizer "Hypnokizer (7 commits)")

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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