PHP Classes

PHP Database Fill: Fill records of MySQL tables with test data

Recommend this page to a friend!
  Info   View files Example   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-06-02 (4 months ago) RSS 2.0 feedNot enough user ratingsTotal: 396 All time: 6,579 This week: 109Up
Version License PHP version Categories
database-fill 0.65GNU General Publi...5.3PHP 5, Databases, Testing


This class can fill records of MySQL tables with test data.

It takes the SQL dump file of a MySQL database and parses it to extract the list of database tables.

The class executes SQL statements to insert records on the MySQL database tables.

The new record field values can be generated randomly or set to a constant value.

The number of records to insert, the range of characters to use in random data and the character set encoding are configurable parameters.

Picture of Martin Latter
  Performance   Level  
Name: Martin Latter <contact>
Classes: 8 packages by
Country: United Kingdom
Age: ???
All time rank: 131261 in United Kingdom
Week rank: 587 Up20 in United Kingdom Up
Innovation award
Innovation award
Nominee: 5x



    * Example to set-up and call databasefiller.class.php
    * Martin Latter, 14/12/2014


ini_set('memory_limit', '256M'); # for inserting a large number of rows ($aConfiguration['num_rows'])

header('Content-Type: text/html; charset=utf-8');

    * Configuration array settings to pass to databasefiller.class.php

$aConfiguration =
# output type toggle
'debug' => false, # set TRUE for verbose screen output and no database insertion, FALSE for database insertion

    # number of rows to insert
'num_rows' => 10,
// optimise mysqld variables in my.cnf/my.ini files when inserting a large number of rows (e.g. 50000)

    # database details
'host' => 'localhost',
'database' => 'dbfilltest',
'username' => 'USERNAME',
'password' => 'PASSWORD',

# schema file
'schema_file' => 'test.sql',

# database connection encoding
'encoding' => 'utf8', # latin1 / utf8 etc

    # random data toggle - set to false for a much faster fixed character fill - but ... no unique indexes permitted
'random_data' => true,

# random character range: ASCII integer values
'low_char' => 33,
'high_char' => 126,

// 'incremental_ints' => true,
    // 'populate_primary_key' => true, # experimental

    # CLI usage: rows of SQL generated before displaying progress percentage
'row_counter_threshold' => 1000

$oDF = new DatabaseFiller($aConfiguration);


  Files folder image Files  
File Role Description
Files folder imageclasses (1 file)
Accessible without login Plain text file basketball.sql Data Auxiliary data
Accessible without login Plain text file databasefiller_example.php Example Example script
Accessible without login Plain text file LICENSE Lic. Auxiliary data
Accessible without login Plain text file Doc. Auxiliary data
Accessible without login Plain text file test.sql Data Auxiliary data

  Files folder image Files  /  classes  
File Role Description
  Plain text file databasefiller.class.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:6,579
This week:109Up
User Comments (1)
6 years ago (muabshir)