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));
?>

I just found a short example here for php, seems pretty awesome certainly the rollback function. omg i learned a lot today ::)

-edit:lol forgot to post it: http://articles.techrepublic.com.com/5100-10878_11-6085922.html

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.