PHP Classes
elePHPant
Icontem

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 (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-12-13 (1 month ago) RSS 2.0 feedNot enough user ratingsTotal: 326 All time: 6,926 This week: 512Up
Version License PHP version Categories
database-fill 0.45GNU General Publi...5.3PHP 5, Databases, Testing
Description Author

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.

  Performance   Level  
Name: Martin Latter is available for providing paid consulting. Contact Martin Latter .
Classes: 5 packages by
Country: United Kingdom United Kingdom
Age: ???
All time rank: 193783 in United Kingdom United Kingdom
Week rank: 96 Up5 in United Kingdom United Kingdom Up
Innovation award
Innovation award
Nominee: 3x

Details

Database Filler

Fill a multi-table MySQL database with test data by parsing the SQL schema file.

Origin

I needed to test the population of a database with 14 complex tables. Tools such as Spawner are useful for small tables - but specifying the datatypes for so many fields (300+) before initiating Spawner would be too time-consuming.

Instead, why not parse the SQL schema?

Purpose

  1. Assist in the testing, editing, and data population of complex database schema, before moving the database to a production environment.
  2. Test database connection encoding and character encoding, and data insertion speeds on different character encodings.
  3. Check table field population with specified datatype, data truncation, visual cues etc.

Database Requirements

  1. The script expects the database schema to exist in MySQL (mysql -u root -p < test.sql).
  2. All table names and column names in the MySQL schema require back-ticks.
  3. Unique keys must be removed from tables when using the option 'random_data' => FALSE

Other

  • Any foreign keys are disabled on data population.
  • The majority of MySQL datatypes are supported.
  • Random character generation is slow in PHP, and further depends on field length, number of fields, and the number of rows being generated.
  • The multiple INSERTs are added in a single query, which is quite fast. Number of INSERTs per second will depend on MySQL configuration settings (default is not optimised), datatype/length inserted, operating system, hardware, etc.

Execution

http://localhost/Database-Filler/databasefiller_example.php

(Or execute on the command-line with: php -f databasefiller_example.php)

License

Database Filler is released under the GPL v.3.

  Files folder image Files  
File Role Description
Plain text file databasefiller.class.php Class Class source
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 README.md Doc. Auxiliary data
Accessible without login Plain text file test.sql Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:326
This week:0
All time:6,926
This week:512Up
User Comments (1)
nice
11 months ago (muabshir)
80%StarStarStarStarStar