2017 © Pedro Peláez
 

database populate-mysql-db

image

tacno/populate-mysql-db

  • Wednesday, January 24, 2018
  • by Tacnoman
  • Repository
  • 1 Watchers
  • 1 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Populate Database (Works only for mysql)

This class populate the table in database with random values. In some cases, we need to view an application with data and this class solve this problem., (*1)

Requirements

  • PDO
  • PHP >= 5.3

How to install:

You need to use the composer:, (*2)

{
    "require": {
        "tokenpost/populate-mysql-db": "dev-master"
    }
}

How to usage:

The class Populate generate random numbers for: * int * bigint * mediumint * smallint * tinyint * float * double, (*3)

and generate texts for * varchar * text, (*4)

There is a class to generate Lorem impsum texts., (*5)

If you want to change a fix value instead a lorem ipsum generator, you can use the method ->setFixValue('<fieldname>','<valuename>');., (*6)

// Example:
....
$populate->setFixValue('image_field','/assets/image/photo.png');

An example

Paragraphs are separated by a blank line., (*7)

try {

    $pdo = new PDO("mysql:host=localhost;dbname=test;charset=utf8",'root','');

    $populate = new Populate();
    $populate->beginWithLoremIpsum(false); // If you want the text beginning with lorem ipsum
    $populate->setPDO($pdo); // set the PDO class

    $populate->setTable('table_test'); // Set the table to populate
    $populate->setFixValue('image_example','/assets/image/photo.jpg'); // if you want a fix value
    echo $populate->insert(100); // The number of inserts
}
catch(Exception $e)
{
    echo $e->getMessage();
}

Another Example


$pdo = new PDO("mysql:host=localhost;dbname=test;charset=utf8",'root',''); $populate = new Populate(); $populate->beginWithLoremIpsum(false); // If you want the text beginning with lorem ipsum $populate->setPDO($pdo); // set the PDO class $populate->setTable('table_test'); // Set the table to populate $populate->setFixValue('image_example','/assets/image/photo.jpg'); // if you want a fix value echo $populate->clean(); // Truncate the table

You can execute via php cli or task., (*8)

Extra

If you want, you can use the Lorem Ipsum generator in your projects. The class Populate\LoremIpsumGenerator use the Singleton like a design pattern., (*9)

An example:, (*10)

$lorem = \Populate\LoremIpsumGenerator::getInstance();

// If u want to generate by a number of words
echo $lorem->generateByWords(30);

// If u want to generate by a number of chars
echo $lorem->generateByChars(30);

// If u want to generate by a paragraph number. The second parameter is if you want to separe by html (tag: 

<

p>)
echo $lorem->generateByParagraph(2,true);

// And if u want to generate a random word
echo $lorem->generateRandomWord();

The Versions

24/01 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

database mysql populate