Jump to content

Could someone critize my population script?


fortnox007

Recommended Posts

Hi all, I prety often populate a database just to test stuff.

So i thought i make a little script which magically populates the database with multiple rows at ones instead of pressing F5 all the time ::). I am not sure if this is the best way so I would love some advice of an expert. If someone can use it feel free to use it. Changing $rows is all that is needed to blast your database to the moon.

 

<?php
include('connector.php');//connection file

//make query
$query = "INSERT INTO comments (title, comment)VALUES";
//$data = mysqli_query("SELECT * FROM comments") or die(mysql_error());
$rows =24;//set to 1 million to get free cookies  and an angry email from your host
$comment =  "Lorem Ipsum is simply dummy";
for ($i=0;$i<$rows;$i++){
    if ($i<($rows-1)){$comma=',';}else{$comma='';}//preventing a comma on last loop which will prolly break query
    $title = chr(rand(97,122)).'this is a title with a bogus prefix';
    $go .= "('$title', '$comment')$comma"; //hoping to get them in this manner ('var1', 'var2')
}
//populate this monkey
mysqli_query($dbc,$query.$go)
    or die('Connect Error: ' . mysqli_error($dbc).'number'.mysqli_errno($dbc));
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.