Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host = 'localhost';
- $dbname = 'mongo';
- $user = 'root';
- $password = '';
- $mysqli = new mysqli($host, $user, $password, $dbname);
- if ($mysqli->connect_errno){
- echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
- exit;
- }
- $start = microtime(true);
- $i = $total = 100000;
- while($i--){
- $j = rand(5, 25);
- $text = '';
- while($j--){
- $text .= chr(rand(97, 122));
- }
- $id = $total - $i;
- echo 'Add '.$id.' => '.$text.PHP_EOL;
- $sql = 'INSERT INTO `basic` (`text`) VALUES (\''.$text.'\');';
- if(!$mysqli->query($sql)){
- echo "Insert failed: (" . $mysqli->errno . ") " . $mysqli->error;
- die;
- }
- }
- $end = microtime(true);
- $result = $end - $start;
- echo "Done in $result seconds".PHP_EOL;
Advertisement
Add Comment
Please, Sign In to add comment