PHPackages                             microweber-packages/microweber-database-manager - 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. microweber-packages/microweber-database-manager

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

microweber-packages/microweber-database-manager
===============================================

Microweber database manager.

0851PHPCI failing

Since Jul 1Pushed 5y agoCompare

[ Source](https://github.com/microweber-packages/microweber-database-manager)[ Packagist](https://packagist.org/packages/microweber-packages/microweber-database-manager)[ RSS](/packages/microweber-packages-microweber-database-manager/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

Database Manager [![Build Status](https://camo.githubusercontent.com/a2fe5cc63bc99078987455ced69540b82ed30355af9df75c5439ebe75ec2fc94/68747470733a2f2f6170692e7472617669732d63692e6f72672f6d6963726f77656265722d7061636b616765732f6d6963726f77656265722d64617461626173652d6d616e616765722e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/a2fe5cc63bc99078987455ced69540b82ed30355af9df75c5439ebe75ec2fc94/68747470733a2f2f6170692e7472617669732d63692e6f72672f6d6963726f77656265722d7061636b616765732f6d6963726f77656265722d64617461626173652d6d616e616765722e7376673f6272616e63683d6d6173746572)
==========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#database-manager-)

Database SAVE
-------------

[](#database-save)

Allows you to save data to ANY table in the database.

### Summary

[](#summary)

```
db_save($table, $data);

```

This is one of the core Microweber function and most of the other *save* functions are really wrappers to this one. It allows you to save data anywhere in any db table.

\*\*Note: This is raw function and does not validate data input or user permissions. \*\*

This function is dangerous and its not meant to be used directly in templates or module views. Better make your own wrapper functions to this one which validates the input and use them when required.

### Usage

[](#usage)

```
$table='content';

$data = array();
$data['id'] = 0;
$data['title'] = 'My title';
$data['content'] = 'My content';
$data['allow_html'] = true; //if true will allow you to save html

$saved = db_save($table,$data);
```

### Parameters

[](#parameters)

parameterdescription`$table`the name of your database table`$data`a key=&gt;value array of your data to save, key must the the name of the db fieldBy default this function removes html tags. In order to save plain html you must set `$data['allow_html'] = true;` in your data array

\#######################

Database GET
------------

[](#database-get)

Allows you to get data from ANY table in the database, and caches the result.

### Summary

[](#summary-1)

db\_get($params);

### Usage

[](#usage-1)

```
$content = db_get('table=content');

foreach ($content as $item) {
    print $item['id'];
    print $item['title'];
    print $item['url'];
    print $item['description'];
    print $item['content'];

}

```

### Parameters

[](#parameters-1)

You can pass parameters as `string` or as `array`. They can be field names in the database table defined with the `table` parameter.

parameterdescriptionusage`table`the name of your database tabledb\_get('table=content')`single`if set to true will return only the 1st row as arraydb\_get('table=content&amp;id=5&amp;single=true')`orderby`you can order by any field namedb\_get('table=content&amp;orderby=id desc')`count`if set to true it will return the results countdb\_get('table=content&amp;count=true')`limit`set limit of the returned dataset, use "no\_limit" to return all resultsdb\_get('table=content&amp;limit=10')`page`set offset of the returned datasetdb\_get('table=content&amp;limit=10&amp;page=2')`page_count`returns the number of result pagesdb\_get('table=content&amp;limit=10&amp;page\_count=true')`$fieldname`you can filter data by passing your fields as paramsdb\_get('table=some\_table&amp;my\_field=value')`keyword`if set it will search for keyworddb\_get('table=content&amp;limit=10&amp;keyword=my title')`nocache`if set to true will skip caching the db resultdb\_get('table=content&amp;nocache=true')### Get everything

[](#get-everything)

```
 //get 5 users
$users = db_get('table=users&limit=5');

//get next 5 users
$users = db_get('table=users&limit=5&page=2');

//get 5 categories
$categories = db_get('table=categories&limit=5');

//get 5 comments
$comments = db_get('table=comments&limit=5');

```

\#######################

Database DELETE
---------------

[](#database-delete)

db\_delete — deletes a record from a database table

### Summary

[](#summary-2)

```
db_delete($table_name, $id = 0, $field_name = 'id')

```

### Return Values

[](#return-values)

`true` or `false` if the item is not deleted

### Usage

[](#usage-2)

```
$category_id = 5;

$delete = db_delete('categories', $category_id);

```

Saving and getting module data
==============================

[](#saving-and-getting-module-data)

Defining Schema
---------------

[](#defining-schema)

When installing a module Microweber checks the `config.php` file for the `$config['tables']` array. Each key represents a table name and its value is an array of column definitions. The ID column is automatically created and all columns are nullable by default.

*Example* `userfiles/modules/paintings/config.php`

```
$config = array();
$config['name'] = "My Paintings";
$config['author'] = "Pablo Picasso";
$config['ui'] = true;
$config['ui_admin'] = true;
$config['position'] = "98";
$config['version'] = "0.01";
$config['tables'] = array(
        'paintings' => array(
            'id' => 'integer',
        	'name' => 'string',
        	'price' => 'float',
        	'description' => 'text',
        	'created_by' => 'integer',
            'created_at' => 'dateTime',
        )
);

```

Custom Tables
-------------

[](#custom-tables)

For more options of the data storage you can read here.

[Read more about making custom tables here](modules_schema.md).

### Getting and saving data

[](#getting-and-saving-data)

You can use the [db\_get](../functions/db_get.md "db_get"), [db\_save](../functions/db_save.md "db_save") and [db\_delete](../functions/db_delete.md "db_delete") functions to work with data from your those tables.

```
// Getting
$data = db_get("table=paintings")

// Saving
$save = array(
	'name' => 'Mona Lisa',
	'description' => 'Paiting by Leonardo da Vinci'
);
$id = db_save('paintings', $save);

// Deleting
db_delete('paintings', $id);

```

#### Create

[](#create)

The `db_save` function accepts table name as first argument and row data as a second argument. In order to create rows in a table simply don't specify an ID.

*Example*

```
$data = array(
	'name' => 'Three Musicians',
	'price' => 2700,
	'description' => 'My greatest work'
);
db_save('paintings', $data);

```

####  Read

[](#-read)

Call the `db_get` function and set the `table` key in the argument array to retrieve rows from a given database table.

*Example*

```
$rows = db_get(array('table' => 'paintings'));

```

Set the `single` key to `true` in the argument array for the function to return a single row. Any non-reserved key name is treated as a `WHERE` condition for given column name. Reference the [`db_get` function docs](../functions/db_get.md) for more details.

*Example*

```
$row = db_get(array(
	'table' => 'paintings',
	'name' => 'Three Musicians',
	'single' => true
	));

```

Alternatively the above query can be written like that `db_get('table=paintings&name=Three Musicians&single=true')`

#### Update

[](#update)

If the `db_save` function receives an array containing an `id` key it performs an update operation on the corresponding row.

*Example*

```
// Gets single row with id = 3
$row = db_get(array(
	'table' => 'paintings',
	'id' => 3,
	'single' => true
	));
$row['title'] = 'My Awesome Painting';
echo 'Updating row with ID ', $row['id'];
db_save('paintings', $row);
```

#### Delete

[](#delete)

The `db_delete` function returns `true` after successfully deleting row with a specified ID.

*Example*

```
db_delete('paintings', $id = 3);

```

Advanced Queries
----------------

[](#advanced-queries)

Reference the [`db_get`](../functions/db_get.md) and [`db_save`](../functions/db_save.md) documentation pages for a list of all available parameters.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/35b70a983b516c0ad00c9d023db03ed818156b8a5b4f3fe17351cf59ea743550?d=identicon)[bobimicroweber](/maintainers/bobimicroweber)

### Embed Badge

![Health badge](/badges/microweber-packages-microweber-database-manager/health.svg)

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M545](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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