PHPackages                             zachleigh/petrol - 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. zachleigh/petrol

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

zachleigh/petrol
================

Framework for parsing text files and writing data to a database.

v0.12.0(6y ago)230MITPHPCI failing

Since Aug 9Pushed 6y ago1 watchersCompare

[ Source](https://github.com/zachleigh/petrol)[ Packagist](https://packagist.org/packages/zachleigh/petrol)[ Docs](https://github.com/zachleigh/petrol)[ RSS](/packages/zachleigh-petrol/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (9)Used By (0)

Petrol
======

[](#petrol)

### Database Fuel

[](#database-fuel)

##### A framework for parsing files and filling databases.

[](#a-framework-for-parsing-files-and-filling-databases)

[![Build Status](https://camo.githubusercontent.com/ec22b64364da93978e817f5767e8d0e029e96a54123214c1907a99000546d732/68747470733a2f2f7472617669732d63692e6f72672f7a6163686c656967682f706574726f6c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/zachleigh/petrol)[![Latest Stable Version](https://camo.githubusercontent.com/12581feeb69c3f95db8555f0bdf2b99695f1873e2777c4a3c4f6c7577a169ead/68747470733a2f2f706f7365722e707567782e6f72672f7a6163686c656967682f706574726f6c2f76657273696f6e2e737667)](//packagist.org/packages/zachleigh/petrol)[![License](https://camo.githubusercontent.com/9c5ebaddda1225f13ccaf5b62b5bed7750be3ac97539fef8451469baa4ef2efb/68747470733a2f2f706f7365722e707567782e6f72672f7a6163686c656967682f706574726f6c2f6c6963656e73652e737667)](//packagist.org/packages/zachleigh/petrol)

### Contents

[](#contents)

##### [Quick Example](#quick-example)

[](#quick-example)

- [Standard Version](#standard-example)
- [Laravel Version](#laravel-example)

##### [Installation](#installation-1)

[](#installation)

##### [Examples](#examples-1)

[](#examples)

##### [Command Library](#commands-1)

[](#command-library)

##### [Database Notes](#database-notes-1)

[](#database-notes)

Quick Example
-------------

[](#quick-example-1)

#### Standard Example

[](#standard-example)

Let's parse a file and fill a Mysql table with **one line of code**.

Our file, **simple.txt**.

```
Bob Smith / bob@example.com / 3974 South Belvie St.
Jean Samson / jean@example.com / 456 North Main
George Higgins / george@example.com / 9844 East South Ave.
Mike Victors / mike@example.com / 987 Cheese Street
Betty Lou Victors / betty@example.com / 987 North Colorado Bvd.
```

We've got names, emails, and address, seperated by spaces and slashes.

Our database table, **simple\_table**.

idnameemailaddressA column for each item in **simple.txt** plus an auto-incrementing id column.

Install Petrol.

```
composer require zachleigh/petrol
```

Navigate to vendor/zachleigh/Petrol in the console and make a .env file.

```
./petrol make env
```

Move **simple.txt** into Petrol/src/Files/.

Make a new filler file.

```
./petrol new simple_table --file=simple.txt
```

Sweet. We now have a FillSimpleTable file in Petrol/src/Fillers/.

Open it up.

```
namespace Petrol\Fillers;

use Petrol\Core\Database\Connection;
use Petrol\Core\Helpers\Traits\Parser;
use Petrol\Core\Helpers\Traits\User;
use Petrol\Core\Helpers\Traits\XmlParser;

class FillSimpleTable extends Filler
{
    use Parser, User;

    /**
     * Database connection class.
     *
     * @var Petrol\Core\Database\Connection
     */
    protected $connection;

    /**
     * Database filling method. If 'auto', Petrol will automatically insert one row
     * every line. If 'manual', insertRow($data) must be called on $this->connection
     * to insert a row. 'dump' will dump results to console instead of filling db.
     *
     * @var string ['auto, 'manual', 'dump']
     */
    protected $fill = 'auto';

    /**
     * The file to be parsed by the Filler. File must be in Petrol/src/Files/.
     *
     * @var string
     */
    protected $file = 'simple.txt';

    /**
     * The database table to be filled. Table must be created before filling.
     *
     * @var string
     */
    protected $table = 'simple_table';

    /**
     * Database table columns excluding id.
     *
     * @var array
     */
    protected $columns = [
        //
    ];

    /**
     * Variables to be declared before loop begins. These variables will be stored
     * on the object and can be accessed with $this->key.
     *
     * @var array
     */
    protected $variables = [
        //
    ];

    /**
     * Construct.
     *
     * @param Connection $connection
     */
    public function __construct(Connection $connection)
    {
        $this->connection = $connection;

        parent::__construct();
    }

    /**
     * Parse the file. Petrol will go through $file line by line and send each line
     * to this parse method.
     *
     * @param string $line [individual lines from file]
     *
     * @return array $data  [array of columns => values for line]
     */
    protected function parse($line)
    {
        // parse file
        //
        // return array;
    }
}
```

Enter the database columns in the $columns array. (We don't need the id column.)

```
    protected $columns = [
        'name',
        'email',
        'address'
    ];
```

Enter your line parsing code in the parse method.

```
    protected function parse($line)
    {
        return array_combine($this->columns, $this->cleanExplode('/', $line));
    }
```

Fill your table.

```
./petrol fill simple_table
```

Done. Reward yourself with a drink of your choice. (A more detailed version of this tutorial can be found [here](#simple-table).)

#### Laravel Example

[](#laravel-example)

Let's parse a file and fill a Mysql table with **one line of code** in a Laravel application.

Our file, **simple.txt**.

```
Bob Smith / bob@example.com / 3974 South Belvie St.
Jean Samson / jean@example.com / 456 North Main
George Higgins / george@example.com / 9844 East South Ave.
Mike Victors / mike@example.com / 987 Cheese Street
Betty Lou Victors / betty@example.com / 987 North Colorado Bvd.
```

We've got names, emails, and address, seperated by spaces and slashes.

Our database table, **simple\_table**.

idnameemailaddressA column for each item in **simple.txt** plus an auto-incrementing id column.

Install Petrol in your application.

```
composer require zachleigh/petrol
```

Register the Petrol service provider in app/Providers/AppServiceProvider.php.

```
public function register()
{
    if ($this->app->environment() == 'local') {
        $this->app->register('Petrol\Core\Providers\PetrolServiceProvider');
    }
}
```

Run `php artisan` and make sure the Petrol commands are listed.

Make the Petrol directory in the app/ directory.

```
php artisan vendor:publish
```

You now have a Petrol directory in /app with Files and Fillers directories in it.

Move **simple.txt** into the Files directory.

Make a new filler file.

```
php artisan petrol:new simple_table --file=simple.txt
```

Sweet. We now have a FillSimpleTable file in app/Petrol/Fillers/.

Open it up.

```
namespace App\Petrol\Fillers;

use Petrol\Core\Database\Connection;
use Petrol\Core\Helpers\Traits\Parser;
use Petrol\Core\Helpers\Traits\User;
use Petrol\Core\Helpers\Traits\XmlParser;

class FillSimpleTable extends Filler
{
    use Parser, User;

    /**
     * Database connection class.
     *
     * @var Petrol\Core\Database\Connection
     */
    protected $connection;

    /**
     * Database filling method. If 'auto', Petrol will automatically insert one row
     * every line. If 'manual', insertRow($data) must be called on $this->connection
     * to insert a row. 'dump' will dump results to console instead of filling db.
     *
     * @var string ['auto, 'manual', 'dump']
     */
    protected $fill = 'auto';

    /**
     * The file to be parsed by the Filler. File must be in Petrol/src/Files/.
     *
     * @var string
     */
    protected $file = 'simple.txt';

    /**
     * The database table to be filled. Table must be created before filling.
     *
     * @var string
     */
    protected $table = 'simple_table';

    /**
     * Database table columns excluding id.
     *
     * @var array
     */
    protected $columns = [
        //
    ];

    /**
     * Variables to be declared before loop begins. These variables will be stored
     * on the object and can be accessed with $this->key.
     *
     * @var array
     */
    protected $variables = [
        //
    ];

    /**
     * Construct.
     *
     * @param Connection $connection
     */
    public function __construct(Connection $connection)
    {
        $this->connection = $connection;

        parent::__construct();
    }

    /**
     * Parse the file. Petrol will go through $file line by line and send each line
     * to this parse method.
     *
     * @param string $line [individual lines from file]
     *
     * @return array $data  [array of columns => values for line]
     */
    protected function parse($line)
    {
        // parse file
        //
        // return array
    }
}
```

Enter the database columns in the $columns array. (We don't need the id column.)

```
    protected $columns = [
        'name',
        'email',
        'address'
    ];
```

Enter your line parsing code in the parse method.

```
    protected function parse($line)
    {
        return array_combine($this->columns, $this->cleanExplode('/', $line));
    }
```

Fill your table.

```
php artisan petrol:fill simple_table
```

Done. Reward yourself with a drink of your choice. (A more detailed version of this tutorial can be found [here](#simple-table).)

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

[](#installation-1)

#### Requirements

[](#requirements)

- ###### PHP 7.1 or higher

    [](#php-71-or-higher)

Linux users can find PHP releases in their distribution repositories. For other operating systems, visit the [php installation guide](http://php.net/manual/en/install.php) for instructions.

- ###### composer

    [](#composer)

Check the [composer documentation](https://getcomposer.org/doc/00-intro.md) for installation instructions.

#### Install

[](#install)

If requirements are met, you can install the package in two ways.

###### Download

[](#download)

Download [here](https://github.com/zachleigh/petrol/releases), cd into the Petrol directory and run

```
composer install
```

Finished. How easy was that?

###### Through composer

[](#through-composer)

```
composer require zachleigh/petrol
```

If you install through composer, the program will be in vendor/zachleigh/petrol

#### A Little Setup

[](#a-little-setup)

###### Executables

[](#executables)

Once you have Petrol installed, you may want to make the 'petrol' file executable so it can be run without having to type php before the command. Not executable:

```
php petrol argument
```

Executable:

```
./petrol argument
```

###### Environment Setup

[](#environment-setup)

You will need to create a .env file and fill in the appropriate information. You can do this manually by copying the .env.example file to .env or by using the built-in command line tool.

```
./petrol make env
```

###### Config File

[](#config-file)

One more step, then you're ready to go. Open up config.php and make sure that 'database' is set to the database of your choice. Currently, only mysql is supported out of the box.

Examples
--------

[](#examples-1)

- [Simple Table](#simple-table)
- [XML Table](#xml-table)
- [XML Table JSON Array](#xml-table-json-array)

#### Simple Table

[](#simple-table)

Let's fill up a simple database.

For this brief tutorial, we will be filling the **simple\_table** Mysql database table with info from the **simple.txt** file. **simple.txt**

```
Bob Smith / bob@example.com / 3974 South Belvie St.
Jean Samson / jean@example.com / 456 North Main
George Higgins / george@example.com / 9844 East South Ave.
Mike Victors / mike@example.com / 987 Cheese Street
Betty Lou Victors / betty@example.com / 987 North Colorado Bvd.
```

We have slash seperated names, email addresses, and physical addresses that need to get into our database.

##### Step 1

[](#step-1)

Before we do anything else, we need to put our data file, **simple.txt**, in Petrol/src/Files/.

##### Step 2

[](#step-2)

Once our file is where it needs to be, we can make a new Filler with the 'new' command. The first argument of the 'new' command is the name of the table, **simple\_table** in our case. The option --file is the name of the file to use, in this case **simple.txt**.

```
./petrol new simple_table --file=simple.txt
```

The Filler will be in Petrol/src/Fillers/ and will be called **FillCamelCasedTableName**, in our case **FillSimpleTable**. It will look something like this.

```
namespace Petrol\Fillers;

use Petrol\Core\Database\Connection;
use Petrol\Core\Helpers\Traits\User;
use Petrol\Core\Helpers\Traits\Parser;

class FillSimpleTable extends Filler
{
    use Parser, User;

    /**
     * Database connection class.
     *
     * @var Petrol\Core\Database\Connection
     */
    protected $connection;

    /**
     * Database filling method. If 'auto', Petrol will automatically insert one row
     * every line. If 'manual', insertRow($data) must be called on $this->connection
     * to insert a row. 'dump' will dump results to console instead of filling db.
     *
     * @var string ['auto, 'manual', 'dump']
     */
    protected $fill = 'auto';

    /**
     * The file to be parsed by the Filler. File must be in Petrol/src/Files/.
     *
     * @var string
     */
    protected $file = 'simple.txt';

    /**
     * The database table to be filled. Table must be created before filling.
     *
     * @var string
     */
    protected $table = 'simple_table';

    /**
     * Database table columns excluding id.
     *
     * @var array
     */
    protected $columns = [
        //
    ];

    /**
     * Variables to be declared before loop begins. These variables will be stored
     * on the object and can be accessed with $this->key.
     *
     * @var array
     */
    protected $variables = [
        //
    ];

    /**
     * Construct.
     *
     * @param Connection $connection
     */
    public function __construct(Connection $connection)
    {
        $this->connection = $connection;

        parent::__construct();
    }

    /**
     * Parse the file. Petrol will go through $file line by line and send each line
     * to this parse method.
     *
     * @param string $line [individual lines from file]
     *
     * @return array $data  [array of columns => values for line]
     */
    protected function parse($line)
    {
        // parse file
        //
        // return $data;
    }
}
```

Let's take a look at it.

- Our file and table names are saved on the object as $file and $table. You shouldn't have to do anything else with these.
- Our filler uses the traits Parser and User. Parser contains general methods to help you parse files and User is where you can put your own functions.
- Our filler is already attached to our database through the $connection object on the class.
- You can choose to auto fill your database (default), fill it manually, or dump it to the console for debugging.
- There is a $columns array where we must enter our database column names.
- There is a $variables array where we can enter variables to be set before looping through the file lines. These will be set on the object and can be accessed with $this-&gt;variable.
- There is a parse method where we will be given the file's lines one at a time.

##### Step 3

[](#step-3)

We now need to set our database columns in the protected $columns array. Our sample file, **simple.txt**, contains names, emails, and address so our database should have **name**, **email**, and **address** columns. We will put these in the $columns array.

```
    protected $columns = [
        'name',
        'email',
        'address'
    ];
```

Note that the column names need to match the columns in the mysql table exactly, excluding an auto-incrementing id column. In this case, our mysql table looks like this:

idnameemailaddress##### Step 4

[](#step-4)

Ok, let's write our parsing logic. Petrol will iterate over $file line-by-line and for each line, it will run the protected method parse(). In parse, we have access to $line, one individual line from the file. We can write our line parsing logic there. The parse() method must return an array representing one row of the database. In other words, we must return a $key =&gt; $value pair array where each $key equals a column name (defined in $columns) and its $value equals the value we wish to assign to that column. In our example, we want to seperate the name, email, and address fields in the file and then assign them to name, email, and address keys in the returned array.

```
    protected function parse($line)
    {
        return array_combine($this->columns, $this->cleanExplode('/', $line));
    }
```

Let's look at this a little deeper. First, we pass $line and '/' (the symbol we want to break the line with) to cleanExplode. cleanExplode is a method in the Parser trait. It is similar to the standard php explode function, except that it also trims white space from each item in the returned array. We then use array\_combine to match the column keys with the values returned from cleanExplode. The resulting data structure looks like this.

```
Array
(
    [name] => Bob Smith
    [email] => bob@example.com
    [address] => 3974 South Belvie St.
)
Array
(
    [name] => Jean Samson
    [email] => jean@example.com
    [address] => 456 North Main
)
Array
(
    [name] => George Higgins
    [email] => george@example.com
    [address] => 9844 East South Ave.
)
Array
(
    [name] => Mike Victors
    [email] => mike@example.com
    [address] => 987 Cheese Street
)
Array
(
    [name] => Betty Lou Victors
    [email] => betty@example.com
    [address] => 987 North Colorado Bvd.
)
```

Notice that the keys in each array equal the $column variable items. This is a must. You've been warned.

##### Step 5

[](#step-5)

We're almost done. After saving the Filler file, we simply run the fill command. The command requires one argument, the database table name. In our case this is **simple\_table**.

```
./petrol fill simple_table
```

And we are done. You just parsed a file and filled a Mysql table with one line of code.

If you're getting errors, you can use the **--errors** flag to dump any Mysql PDO errors you may be getting. You can also set $fill to 'dump' to dump to the console instead of filling your database.

#### XML Table

[](#xml-table)

In this short tutorial, we'll be filling a table using an XML file. We will be using the **books.xml** file and filling the **books** table in our database. **books.xml**

```

      Gambardella, Matthew
      XML Developer's Guide
      Computer
      44.95
      2000-10-01
      An in-depth look at creating applications
      with XML.

      Ralls, Kim
      Midnight Rain
      Fantasy
      5.95
      2000-12-16
      A former architect battles corporate zombies,
      an evil sorceress, and her own childhood to become queen
      of the world.

      Corets, Eva
      Maeve Ascendant
      Fantasy
      5.95
      2000-11-17
      After the collapse of a nanotechnology
      society in England, the young survivors lay the
      foundation for a new society.

      Corets, Eva
      Oberon's Legacy
      Fantasy
      5.95
      2001-03-10
      In post-apocalypse England, the mysterious
      agent known only as Oberon helps to create a new life
      for the inhabitants of London. Sequel to Maeve
      Ascendant.

      Corets, Eva
      The Sundered Grail
      Fantasy
      5.95
      2001-09-10
      The two daughters of Maeve, half-sisters,
      battle one another for control of England. Sequel to
      Oberon's Legacy.

      Randall, Cynthia
      Lover Birds
      Romance
      4.95
      2000-09-02
      When Carla meets Paul at an ornithology
      conference, tempers fly as feathers get ruffled.

      Thurman, Paula
      Splish Splash
      Romance
      4.95
      2000-11-02
      A deep sea diver finds true love twenty
      thousand leagues beneath the sea.

      Knorr, Stefan
      Creepy Crawlies
      Horror
      4.95
      2000-12-06
      An anthology of horror stories about roaches,
      centipedes, scorpions  and other insects.

      Kress, Peter
      Paradox Lost
      Science Fiction
      6.95
      2000-11-02
      After an inadvertant trip through a Heisenberg
      Uncertainty Device, James Salway discovers the problems
      of being quantum.

      O'Brien, Tim
      Microsoft .NET: The Programming Bible
      Computer
      36.95
      2000-12-09
      Microsoft's .NET initiative is explored in
      detail in this deep programmer's reference.

      O'Brien, Tim
      MSXML3: A Comprehensive Guide
      Computer
      36.95
      2000-12-01
      The Microsoft MSXML3 parser is covered in
      detail, with attention to XML DOM interfaces, XSLT processing,
      SAX and more.

      Galos, Mike
      Visual Studio 7: A Comprehensive Guide
      Computer
      49.95
      2001-04-16
      Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are
      integrated into a comprehensive development
      environment.

```

We have 12 books, each with an id stored as an attribute on the book tag, an author, a title, a genre, a price, a publish date, and a description. In this tutorial, we will be filling a table that has one column for each field. Our database will look like this:

idbook-idauthortitlegenrepricepublish-datedescription##### Step 1

[](#step-1-1)

Move **books.xml** into Petrol/src/Files.

##### Step 2

[](#step-2-1)

Make an new Filler with the new command.

```
./petrol new books --file=books.xml
```

##### Step 3

[](#step-3-1)

In the newly created FillBooks file, enter the database columns in the $columns array.

```
    protected $columns = [
        'book-id',
        'author',
        'title',
        'genre',
        'price',
        'publish_date',
        'description'
    ];
```

##### Step 4

[](#step-4-1)

Next, we need to write our parsing logic. Because this is an XML file, we can use the XmlParser helper trait. At the top of the FillBooks file, add XmlParser to the list of traits.

```
class FillBooksColumns extends Filler
{
    use Parser, User, XmlParser;
    ...
```

We will also need to fill our table manually, so set $fill to 'manual'.

```
protected $fill = 'manual';
```

Now we can use all the methods available in XmlParser to help us.

```
    protected function parse($line)
    {
        $this->setRootTag('catalog');

        $array = $this->xmlToArrays($line, 'book');

        if (!is_null($array)) {
            $book_id = $this->getAttributeFromArray($array, 'id');

            $data = $this->arrayToData($array, $this->columns);

            $data['book_id'] = $book_id;

            print_r($data);

            $this->connection->insertRow($data);
        }
    }
```

Let's have a look at this. First, when using the the XmlParser helpers, we need to set the root XMNL tag with setRootTag(). This identifies when the XML to be read actually starts and makes parsing easier. Because we want to get an attribute (book\_id) as well, we are going to have to do a two step parse. First, we will convert each book tree into an array with xmlToArrays(). This method requires $line and the root tag of the tree you want to convert to an array, in our case 'book.' This will return null unless the closing book tag has been reached, in which case it will return an array. Because the xmlToArrays method returns null unless the closing tag has been reached, we need to check for null before proceeding.

Once we get our array, we can get the 'book\_id' attribute off the array with the getAttributeFromArray method. (Note that this method is still in development and needs to be tested more.) Once we have the attribute, we can convert our array to a data array with arrayToData, which requires the array we generated before as well as $columns. This method will return a $key =&gt; $value pair array where $key is a column name and $value is a value from the XML file.

We then simply place 'book\_id' on the returned data array and manually insert the row with $this-&gt;connection-&gt;insertRow.

If we didnt have to get the 'book\_id' attribute, this would have been even easier. Instead of converting the XML to an array and then converting the array to returnable data, we could have simply converted the XMl directly to a data array.

```
    protected function parse($line)
    {
        $this->setRootTag('catalog');

        $data = $this->xmlToData($line, 'book', $this->columns);

        if (!is_null($data)) {
            $this->connection->insertRow($data);
        }
    }
```

##### Step 5

[](#step-5-1)

All we have to do now is fill our table.

```
./petrol fill books
```

Finished.

#### XML Table JSON Array

[](#xml-table-json-array)

In some situations, it is better to enter the XML data into a database as a JSON array. This isn't always desired because it makes searching the database more difficult and requires decoding of the returned values, but for some situations, this is a good way to go about handling XML data.

This very brief tutorial is similar to the previous tutorial, except our database table and our parsing function will be different. Our database structure:

idbook\_idinfoSo in our Filler file, our columns array will look like this:

```
    protected $columns = [
        'book_id',
        'info'
    ];
```

Our parsing function will look like this:

```
    protected function parse($line)
    {
        $this->setRootTag('catalog');

        $array = $this->xmlToArrays($line, 'book');

        if (!is_null($array)) {
            $data['book_id'] = $this->getAttributeFromArray($array, 'id');

            $data['info'] = json_encode($array);

            $this->connection->insertRow($data);
        }
    }
```

Rather than convert the array returned from xmlToArrays into an array that can be fed to our Mysql statement, we will instead json encode it. When you get the database value on the other end, you can simply use json\_decode to get back the original structure of the array. Its not for every situation, but in some cases its the best solution.

Command Library
---------------

[](#command-library-1)

- [fill](#fill)
- [make](#make)
- [new](#new)

### fill

[](#fill)

Fill a database table using the Filler made with the **new** command. table\_name needs to match name of database table used when creating the Filler.

```
./petrol fill table_name [--options]
```

##### Options

[](#options)

###### errors

[](#errors)

Dump Mysql PDO errors

```
./petrol fill table_name --errors
```

###### quiet

[](#quiet)

Quiet all user input prompts.

```
./petrol fille table_name --quiet
```

### make

[](#make)

Make something

```
./petrol make thing_to_make
```

##### Things you can make

[](#things-you-can-make)

###### env

[](#env)

Make a .env file with database credentials

```
./petrol make env
```

### new

[](#new)

Make a new Filler to parse a file and fill a database table. table\_name needs to match the database table name.

```
./petrol new table_name [--options]
```

##### Options

[](#options-1)

###### file

[](#file)

Set the file to be used by the Filler.

```
./petrol new table_name --file=example_file.txt
```

###### path

[](#path)

Set the new Filler save location. (For testing purposes only.)

Database Notes
--------------

[](#database-notes-1)

##### Requirements

[](#requirements-1)

Your database must meet the following requirements:

- Tables must have an auto-incrementing 'id' column
- Column names must exactly match the expected field names.

##### Other database types

[](#other-database-types)

Currently, only Mysql is supported. The database connection uses php PDO drivers that can be changed out fairly easily. Currently, PDO supports 12 database types. Check the [driver list](http://php.net/manual/en/pdo.drivers.php) for more information. If you wish to make an adapter for one of these database types, adapter name rules must be followed.

- Cuprid: **CupridDatabase**
- FreeTDS / Microsoft SQL Server / Sybase: **DblibDatabase**
- Firebird: **FirebirdDatabase**
- IBM DB2: **IbmDatabase**
- IBM Informix Dynamic Server: **InformixDatabase**
- MySQL: **MysqlDatabase**
- Oracle Call Interface: **OciDatabase**
- ODBC v3 (IBM DB2, unixODBC and win32 ODBC): **OdbcDatabase**
- PostgreSQL: **PgsqlDatabase**
- SQLite 3 and SQLite 2: **SqliteDatabase**
- Microsoft SQL Server / SQL Azure: **SqlsrvDatabase**
- 4d: **FourD** (A class naming rule exception exists for this, but it is untested)

The adapter class should be in its own file in src/Core/Database/Databases/ and must implement DatabaseInterface. If you make a new adapter, please let me know so I can include it in the main program. If you dont know how to write a new adapter, let me know and I'll do it if time permits.

Besides making an adapter, you will also have to make a new array for the database type in 'connections' in config.php.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Recently: every ~393 days

Total

7

Last Release

2326d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/00a76b63e84a85f8770b1b02b1190c03400c48528f0c33262f7789d35eca875d?d=identicon)[zachleigh](/maintainers/zachleigh)

---

Top Contributors

[![zachleigh](https://avatars.githubusercontent.com/u/5616626?v=4)](https://github.com/zachleigh "zachleigh (25 commits)")

---

Tags

databaseseederseedfillfiller

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zachleigh-petrol/health.svg)

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

###  Alternatives

[jlapp/smart-seeder

Smart Seeder adds the same methology to seeding that is currently used with migrations in order to let you seed in batches, seed to production databases or other environments, and to rerun seeds without wiping out your data.

1903.1k](/packages/jlapp-smart-seeder)[eighty8/laravel-seeder

Versioned, environment-based Seeders in Laravel

1857.1k](/packages/eighty8-laravel-seeder)[perplorm/perpl

Perpl is an improved and still maintained fork of Propel2, an open-source Object-Relational Mapping (ORM) for PHP.

203.7k](/packages/perplorm-perpl)[zachleigh/yarak

Laravel inspired devtools for Phalcon. Database migrations, model factories and database seeders.

293.8k](/packages/zachleigh-yarak)

PHPackages © 2026

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