dev-master
9999999-dev
MIT
The Requires
- php >=5.3.0
database mysql populate
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)
You need to use the composer:, (*2)
{ "require": { "tokenpost/populate-mysql-db": "dev-master" } }
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');
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(); }
$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)
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();
MIT
database mysql populate