Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Stop a PHP mysqli_query() loop without restarting MySQL?

Codes here !

Moderators: macek, egami, gesf

Stop a PHP mysqli_query() loop without restarting MySQL?

Postby Snip3r95 » Mon Jun 23, 2014 12:40 am

Last night I couldn't sleep and decided to test the limits of a MySQL database. I should note that I am just beginning to learn PHP and MySQL, I figured I would try and break it to see if anything interesting would happen. I wrote a quick PHP script that generates 99,999,999 tables with random names to see if it would cause any noticeable slowdown or problems in general.

The tables took a while to generate (about 2 per second) so now I have a script that is going to create random tables for the next 82 weeks and I have no idea how to stop it without restarting PHP and MySQL. Is there a way to stop a script like this, short of a complete restart? I'll post my code below.

Code: Select all
<?php
$con = mysqli_connect("localhost", "root", "root", "will_it_break"); //create connection, store to variable "con"

// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

//create random string
function generate_random_string($name_length = 8) {
   $letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
   return substr(str_shuffle($letters), 0, $name_length);
}

// Create a table 99999999 times
for($i = 0; $i <= 99999999; $i++)
{
   $n = generate_random_string(8);
   $k = generate_random_string(8);
   $z = generate_random_string(8);
   $sql="CREATE TABLE $n($k CHAR(30),$z CHAR(30))";
   mysqli_query($con,$sql);
   $i++;
}

// Check if table was created
if (mysqli_query($con,$sql)) {
  echo "You now have a shitload of tables";
} else {
  echo "Error creating table: " . mysqli_error($con);
}
?>
Snip3r95
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Jun 23, 2014 12:24 am

Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.