Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Connect to a MySQL database using driver invocation */
- $dsn = 'mysql:dbname=test;host=mysql-host';
- $user = 'root';
- $password = 'test';
- try {
- $dbh = new PDO($dsn, $user, $password);
- echo '<h1 style="text-align: center; color: blue;">Success</h1>';
- } catch (PDOException $e) {
- echo 'Connection failed: ' . $e->getMessage();
- }
- echo '<pre>';
- $mc = new Memcached();
- $mc->addServer("memcached", "11211");
- $cachedResults = $mc->get('results');
- if ($cachedResults)
- {
- echo '<h2>Results from Cache:</h2>';
- foreach ($cachedResults as $row) {
- print $row['emri'] . "\t";
- print $row['mbiemri'] . "\t";
- print $row['email'] . "\n";
- $results[] = $row;
- }
- }
- else
- {
- $results = [];
- $sql = 'SELECT * FROM students ORDER BY emri';
- foreach ($dbh->query($sql) as $row) {
- print $row['emri'] . "\t";
- print $row['mbiemri'] . "\t";
- print $row['email'] . "\n";
- $results[] = $row;
- }
- $mc->set('results', $results);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement