PHP Classes
elePHPant
Icontem

DB Populator: Populate a MySQL database with random data

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2010-08-05 (4 years ago) RSS 2.0 feedStarStarStarStar 68%Total: 891 This week: 5All time: 3,725 This week: 231Up
Version License PHP version Categories  
db-populator 1.0.0BSD License5.0PHP 5, Databases, Testing
Description Author  

This class can be used to populate a MySQL database with random data.

It can scan the list of tables and fields of a MySQL database and generate SQL INSERT statements that will fill the tables with records with random data.

The class tries to populate each record field with values that seem appropriate based on the field name.

Then it can either execute the generated SQL statements or save them to a file.

Innovation Award  
PHP Programming Innovation award winner
September 2010
Winner


Prize: One copy of the Zend Studio
When you need to test database applications it is convenient to test them with different values in the database records.

This class helps testing database applications by filling table records with random data in different record fields which can be used to test the application with different combinations of values.

Manuel Lemos
Picture of Rafael Jaques
Name: Rafael Jaques <contact>
Classes: 1 package by
Country: Brazil Brazil
Age: 26
All time rank: 2317163 in Brazil Brazil
Week rank: 272 Up23 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Details provided by the author  
DataBase Populator Class

1. What is it all about?

When one finishes the database modeling and it's time to integrate with
the application, many times the problem is the DATA!
You don't have data on the database in order to make the tests.
This class was developed to fill this gap, providing a simple way to
populate your database with dummy data.


2. How to use it?

Just include the class and create a new instance.

    require('dbpopulator.class.php');
    $db = new DBPopulator();

After that, provite the database access information.

    $db->setDb('localhost', 'user', 'pass');

Use the method 'populate' with the following parameters:

    * tables [mandatory]
        Use string or array to define this value.
        Either way, the pattern to specify the table is 'database.table'.
        You can also use * to populate all tables within a database (database.*)
    
    * inserts
        Use this parameter to specify the number of rows to be inserted at each table.
        
    * asScript
        Define here a filename to create the SQL statements instead of running the code
        directly in the database.
    
Example (generating a script to populate two tables with 20 records each):

    $db->populate(array('mydb.table1', 'mydb.table2'), 20, 'my_script.sql');
    
    
3. Customisation

At the very beggining of the class you'll find the variables that you can modify
in order to suit your needs.

Here they are:

    * Field name pattern ($dummyName, $dummyAge, $dummyLink, ...)
        You can use these variables to set the field names to generate more
        consistent data into your tables.
        The script will try to match these field names and do the association
        with related data.
    
    * Password encrypt ($dummyPasswordEncrypt)
        Change as you need if you want to encrypt your generated passwords.
        Values can be: md5, sha1, base64, false
        
    * Number range ($dummyIntRange, $dummyRealRange)
        Define the minimum and maximum values to generate numbers.
        
    * Dummy values catalog 
        Use this variables to set the values for generation dummy data.
    
  Files folder image Files  
File Role Description
Plain text file dbpopulator.class.php Class A class to populate your MySQL
Accessible without login Plain text file example.php Example Example of usage
Plain text file LICENSE Lic. BSD License
Accessible without login Plain text file README Doc. Purpose, HowTo and Customising
Plain text file TODO Data TODO list

 Version Control Unique User Downloads Download Rankings  
 0%Total:891All time:3,725
 This week:5This week:231Up
User Ratings User Comments (1)  
 All time
Utility:85%StarStarStarStarStar
Consistency:90%StarStarStarStarStar
Documentation:80%StarStarStarStarStar
Examples:90%StarStarStarStarStar
Tests:-
Videos:-
Overall:68%StarStarStarStar
Rank:315