[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Php mysql random data generator

Posted on 2009-12-27
4
Medium Priority
?
342 Views
Last Modified: 2013-12-12
Hi,
I need a php script that generate 1.000.000 lines in my mysql table with structure attached in code.

The PrimaryImei should be always 15 numbers.
The other fileds should have randoming lenght and could have characters and numbers.

Thanks


CREATE TABLE table (
  ASCnumber varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  StatoLavorazione varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  Modello varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  CustomerType varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  CustomerLastName varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  CustomerFirstName varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  CustomerPhoneNumber varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  WorkOrderId varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  ServiceCode varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  PrimaryImei varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  AdditionalSerialNumber varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  ProductCode varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  SwVersion varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  NewSwVersion varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  PopDate varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  WarrantyStatus varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  Vid varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  SpecialWarrantyId varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  ReceivingDate varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  ShippingDate varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  SwapDate varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  SwapReasonCode varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  SwapImei varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  RepSymCode1 varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  FaultCode1 varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  KeyRepair1 varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  PartNumber1 varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  CctRef1 varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  RepairModule1 varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  PartReplaced1 varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  ID int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (ID)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Open in new window

0
Comment
Question by:nokiamobile
  • 2
4 Comments
 
LVL 15

Expert Comment

by:ludofulop
ID: 26127421
easy way is   md5(time().rand())  
if you need a string of specified length, user substr for result of above function
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26127591
The message digest is always 32 characters.  To make your testing easier, you might want to prepend the name of the column to the md5() string.  So, for example all of your rows for "FaultCode1" would have data in them that looked like this:

FaultCode1_aeca84e8f299549a00f32003284ac333

Interesting question - why are you doing this? ~Ray
0
 

Author Comment

by:nokiamobile
ID: 26127780
Could you help me to create the script to add the values on mysql table, satisfing my requirments?

I need to populate the DB to test the performance during search.

Thanks
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 26127797
It's a lot of typing and testing - just app-dev work.  You gotta do that, but I would be glad to show you how I might go about it.

Let's take this subset for an example.  You would do something like this for each column and then insert all the columns.  Repeat a million times.  Your insert script will probably time out and blow up on you.  No problem - just check the last insert_id value and restart with a counter set to a million minus the number already inserted.

Your most important performance characteristics will come from how you index the columns that are used in your WHERE clauses.

Best regards, ~Ray


// POPULATE VARIABLES WITH DATA
$ASCnumber        = 'ASCnumber_' . md5(rand());
$StatoLavorazione = 'StatoLavorazione_' . md5(rand());

// NOW CREATE AND RUN THE INSERT QUERY
$sql = "INSERT INTO table ( ASCnumber, StatoLavorazione ) VALUES ( '$ASCnumber', '$StatoLavorazione' )";

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month18 days, 23 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question