Recommend this page to a friend!
  Classes of Rafael Jaques  >  DB Populator  >  README  >  Download  
Role: Documentation
Content type: text/plain
Description: Purpose, HowTo and Customising
Class: DB Populator
Populate a MySQL database with random data
Author: By
Last change: Misspelling fix.
Date: 11 years ago
Size: 2,213 bytes


Class file image Download
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.

    $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.
For more information send a message to info at phpclasses dot org.