fork download
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <title>Document</title>
  9. </head>
  10. <body>
  11. <table>
  12. <tr>
  13. <th>id</th>
  14. <th>user name</th>
  15. <th>name</th>
  16. <th>email</th>
  17. </tr>
  18. <?php
  19. $servername = 'localhost';
  20. $dbname = 'test';
  21. $username = 'root';
  22. $password = '';
  23. try {
  24. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  25. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  26. $sql = "SELECT * FROM user";
  27. $results = $conn->query($sql);
  28. foreach ($results as $results) {
  29. ?>
  30. <tr>
  31. <td><?php echo $results['id'] ?></td>
  32. <td><?php echo $results['username'] ?></td>
  33. <td><?php echo $results['name'] ?></td>
  34. <td><?php echo $results['mail'] ?></td>
  35. </tr>
  36. <?php
  37. }
  38. } catch (PDOException $e) {
  39. echo $e->getMessage();
  40. }
  41. $conn = null;
  42. ?>
  43. </table>
  44. </body>
  45. </html>
Success #stdin #stdout 0.02s 24620KB
stdin
Standard input is empty
stdout
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<table>
    <tr>
        <th>id</th>
        <th>user name</th>
        <th>name</th>
        <th>email</th>
    </tr>
    could not find driver</table>
</body>
</html>