Advertisement
Guest User

Untitled

a guest
Jan 5th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. $host = '127.0.0.1';
  2. $db   = 'cns';
  3. $user = 'root';
  4. $pass = 'password';
  5. $charset = 'utf8mb4';
  6.  
  7. $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
  8. $options = [
  9.     PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
  10.     PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  11.     PDO::ATTR_EMULATE_PREPARES   => false,
  12. ];
  13. try {
  14.      $pdo = new PDO($dsn, $user, $pass, $options);
  15.  
  16.      $start = microtime(true);
  17.      for ($t = 1; $t <= 150; $t++) {
  18.    echo $t.PHP_EOL;
  19.       $stmt = $pdo->query('select * from history_datas where coins_id = '.$t.' order by created_at desc');
  20.   while ($row = $stmt->fetch())
  21.   {
  22.       //echo "\t".$row['coins_id'].'-'.$row['created_at'] . "\n";
  23.   }
  24.  }
  25.  echo (microtime(true) - $start).PHP_EOL;
  26. } catch (\PDOException $e) {
  27.      throw new \PDOException($e->getMessage(), (int)$e->getCode());
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement