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

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

ismail1432/database-anonymizer
==============================

Database anonymizer.

v0.0.4(5y ago)014MITPHPPHP ^7.1.3

Since Mar 31Pushed 5y agoCompare

[ Source](https://github.com/ismail1432/database-anonymizer)[ Packagist](https://packagist.org/packages/ismail1432/database-anonymizer)[ Docs](https://webnet.fr)[ RSS](/packages/ismail1432-database-anonymizer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (6)Used By (0)

Database anonymizer
===================

[](#database-anonymizer)

[![Build Status](https://camo.githubusercontent.com/eba7baa52bbf23f15e39260b3abb885ae0926c1577496a236a33da3bdd2b6b1e/68747470733a2f2f7472617669732d63692e636f6d2f7765626e65742d66722f64617461626173652d616e6f6e796d697a65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/webnet-fr/database-anonymizer)[![codecov](https://camo.githubusercontent.com/7bf4e7a8ce845f10095b6692a40351dc8047468150f095e1683d2539b930faca/68747470733a2f2f636f6465636f762e696f2f67682f7765626e65742d66722f64617461626173652d616e6f6e796d697a65722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/webnet-fr/database-anonymizer)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/896d6d580846183c049e5fd875b1686e5990bd6ca66fb6a10497b3147bdf23ad/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7765626e65742d66722f64617461626173652d616e6f6e796d697a65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/webnet-fr/database-anonymizer)

### Why ?

[](#why-)

[General Data Protection Regulation](https://en.wikipedia.org/wiki/General_Data_Protection_Regulation) (GDPR) imposes strict rules in the domain of information storage and treatment. You must not treat the users' personal data unless there is a strong necessity. In case you want to dump a production database in order to use it during development you cannot store or use peronal data in a dumped database anymore. You must delete or anonymize personal information before importing a production database in your developpment setting.

### How ?

[](#how-)

Launch a command provided by our **database anonymizer** and it will replace personal information with random but meaningful data:

```
php bin/database-anonymizer webnet-fr:anonymizer:anonymize  -U
```

- Path to &lt;config.yaml&gt; is required. Check out the next section to find out how to write a configuration.
- Numerous options to define a database connection are available:
    - `--url=` or `-U` to define a database connection string. It is a very convenient option because it alone is capable to define your database connection.
    - `--type=` or `-t` to define a driver to use (`mysql`, `mysqli`, `pdo_pgsql`, `sqlsrv`).
    - `--host=` or `-H` to define a database host.
    - `--port=` or `-P` to define a port of the database server.
    - `--database=` or `-d` to define a port of the database server.
    - `--user=` or `-u` to define a username to access the database server.
    - `--password=` or `-p` to define a password to access the database server.

### How to install ?

[](#how-to-install-)

Two options are provided:

1. If you develop a PHP project you are welcome to add a dependency (maybe with `--dev` option):

```
composer require webnet-fr/database-anonymizer
```

2. [Use Docker](#launch-anonymizer-in-a-docker-container) if you don't use PHP or for any other reason.

### How to configure the fields to anonymize ?

[](#how-to-configure-the-fields-to-anonymize-)

The good point is that you can specify the fields to anonymize and how they will be anonymized:

```
webnet_fr_database_anonymizer:  # required part of configuration
  tables:
    users:                      # table name
      primary_key: [id]         # indicate primary key
      fields:
        email:                  # field's name to anonymize
          generator: faker      # chose a generator
          formatter: email      # chose one of dozens of the faker's formatters
          unique: ~             # assure that the random value will be unique
        name:                   # another field to anonymize
          generator: faker      # generator
          formatter: name       # formatter
          arguments: ['female'] # specify the arguemnts to pass to the formatter

```

`primary_key` entry is optional and can be inferred automatically. You can indicate a composite primary key or any column with a unique non-null value.

### Let anonymizer guess the configuration

[](#let-anonymizer-guess-the-configuration)

While the configuration of all your database tables can be tedious we provide you with a guesser. The guesser command enable you to construct automatically the configuration:

```
php bin/database-anonymizer webnet-fr:anonymizer:guess-config -f -U
```

The guesser verifies all columns in all tables in your database searching for columns possibly containing sensitive personal data like first name, birth date, social security number, etc.

You can pass the following arguments and options to the guess command:

- `--file=` or `-F=` to write configuration to a file. Otherwise the configuration will pop out to your console.
- `-U`, `-t`, `-H`, `-P`, `-d`, `-u`, `-p` options are at your disposal to specify a database connection.

### What generators are available ?

[](#what-generators-are-available-)

Out of the box two types of generators are available :

1. [Constant](src/Generator/Constant.php) generator :

```
webnet_fr_database_anonymizer:
    tables:
        :
            fields:
                password:
                    generator: constant # specify "constant" generator
                    value: pass123      # all rows will be set to "pass123"
```

2. [Faker](https://github.com/fzaninotto/Faker)'s generators. This tool makes use of `fzaninotto/faker` library. Anonymizer lets you use all formatters provided by Faker. We invite you check them out. Here is couple of examples :

```
webnet_fr_database_anonymizer:
    tables:
        :
            fields:

                # Set "birthdate" field to a random date in a range from -100 to -18 years.
                birthdate:
                    generator: faker
                    formatter: dateTimeBetween
                    arguments: ['-100 years', '-18 year']
                    date_format: Y-m-d
                    optional: 0.4

                # Set "numero_ss" field to a random number of the french sécurité sociale.
                # Pay attention that "nir" formatter is available only with french locale.
                numero_ss:
                    generator: faker
                    formatter: nir
                    locale: fr_FR

                # Set "tax_code" field to a random tax code for russian company.
                # Pay attention that "kpp" formatter is available only with russian locale.
                tax_code:
                    generator: faker
                    formatter: kpp
                    locale: ru_RU
                    unique: ~
```

For each faker generator you can specify these options :

- `formatter` - any available formatter in any available provider. E.g. `randomDigit`, `name`, `email`, `cpr` (for `da_DK` locale only).
- `locale` - any available locale in Faker. Pay attention that certain formatters exist exclusively for certain locales. E.g. `cs_CZ`, `da_DK`, `ru_RU`.
- `unique` - assures that each generated value is unique in the scope of current field. This is useful for generating usenames. Beware of overflow exceptions.
- `optional` - with a certain chance a generated value will be null. When you set `optional: 0.4` you have 40% chance of random meaningful value and 60% chance of null.
- `date_format` - if a generated value is `DateTime` object you must specify a format. This is true for these formatters: `dateTimeBetween`, `dateTimeInInterval`, `dateTimeThisYear`, etc. E.g `Y-m-d`, `Y-m-d H:i:s` or any valid format for [php date() function](https://www.php.net/manual/fr/function.date.php).

### Truncate tables

[](#truncate-tables)

There is a possibility to point tables to truncate:

```
webnet_fr_database_anonymizer:
    tables:
        :
            truncate: true
```

Pay attention that foreign keys constraint are deactivated while truncating tables. You risk to end up with foreign key inconsistency.

### Launch anonymizer in a docker container

[](#launch-anonymizer-in-a-docker-container)

Then take advantage of Docker.

1. Install [Docker](https://www.docker.com).
2. Place the [docker/Dockerfile](docker/Dockerfile) in an empty folder. Delete unnecessary extension installation (MySQL, PostgreSQL, SQL Seriver) to speed up the docker build.
3. Create the anonymizer configuration in, say, `config.yaml`.
4. Build an image.

```
docker build -t webnetfr/anonymizer .

```

4. Run anonymization.

```
docker run --volume : \
    webnetfr/anonymizer \
    php vendor/bin/database-anonymizer --no-interaction --url

```

Where:

- ``
- `` is a path for your configuraion in the container accessible by anonymizer. I suggest you to always use `/var/www/anonymizer/config.yaml`
- `` is the URL to your database (e.g. `mysql://user:password@host:port/name`). Check out the command options if you prefer to pass the `host`, `port`, `user`, `password`values in separate options.
- `` is the same as ``but you can indicate the path relative to `/var/www/anonymizer`. That said you can simply put `config.yaml` if you used `/var/www/anonymizer/config.yaml` in ``.

Imagine you downloaded the [docker/Dockerfile](docker/Dockerfile) into an empty folder and created `conf.yml` next to it. Your command may be:

```
docker run --volume $(pwd)/conf.yaml:/var/www/anonymizer/config.yaml \
    webnetfr/anonymizer \
    php vendor/bin/database-anonymizer -n -Umysql://root:pass@localhost/db config.yaml

```

*Tip*: check out the variety of different options Docker provides you with. For example you may add the `--net=host` option to share your machine's network with the container.

*Tip*: you can run and connect to the container with this command :

```
docker run --volume $(pwd)/conf.yaml:/var/www/anonymizer/config.yaml -it \
    webnetfr/anonymizer bash

```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.1% 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 ~234 days

Total

4

Last Release

1899d ago

### Community

Maintainers

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

---

Top Contributors

[![ismail1432](https://avatars.githubusercontent.com/u/13260307?v=4)](https://github.com/ismail1432 "ismail1432 (4 commits)")[![webnet-fr](https://avatars.githubusercontent.com/u/16704392?v=4)](https://github.com/webnet-fr "webnet-fr (2 commits)")[![cdaguerre](https://avatars.githubusercontent.com/u/4642448?v=4)](https://github.com/cdaguerre "cdaguerre (1 commits)")

---

Tags

phpdatabaseanonymizer

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[webnet-fr/database-anonymizer

Database anonymizer.

3733.8k3](/packages/webnet-fr-database-anonymizer)[bartlett/php-compatinfo-db

Reference Database of all functions, constants, classes, interfaces on PHP standard distribution and about 110 extensions

1183.0k1](/packages/bartlett-php-compatinfo-db)

PHPackages © 2026

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