Advertisement
Guest User

Untitled

a guest
Feb 1st, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. /* Connect to a MySQL database using driver invocation */
  5. $dsn = 'mysql:dbname=test;host=mysql-host';
  6. $user = 'root';
  7. $password = 'test';
  8.  
  9. try {
  10.     $dbh = new PDO($dsn, $user, $password);
  11.     echo '<h1 style="text-align: center; color: blue;">Success</h1>';
  12. } catch (PDOException $e) {
  13.     echo 'Connection failed: ' . $e->getMessage();
  14. }
  15.  
  16. echo '<pre>';
  17.  
  18. $mc = new Memcached();
  19. $mc->addServer("memcached", "11211");
  20.  
  21. $cachedResults = $mc->get('results');
  22.  
  23. if ($cachedResults)
  24. {
  25.     echo '<h2>Results from Cache:</h2>';
  26.     foreach ($cachedResults as $row) {
  27.         print $row['emri'] . "\t";
  28.         print $row['mbiemri'] . "\t";
  29.         print $row['email'] . "\n";
  30.         $results[] = $row;
  31.     }
  32. }
  33. else
  34. {
  35.     $results = [];
  36.     $sql = 'SELECT * FROM students ORDER BY emri';
  37.     foreach ($dbh->query($sql) as $row) {
  38.         print $row['emri'] . "\t";
  39.         print $row['mbiemri'] . "\t";
  40.         print $row['email'] . "\n";
  41.         $results[] = $row;
  42.     }
  43.     $mc->set('results', $results);
  44. }
  45.  
  46.  
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement