SHARE
TWEET

Untitled

a guest Jun 12th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     <?php
  2.     $servername = "<IP_address>";
  3.     $username = "<user_name>";
  4.     $password = "<user_password>";
  5.     $dbname = "<Database_name>";
  6.     try {
  7.         $dbh = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  8.     }catch(PDOException $e) {
  9.         die('Error');
  10.     }
  11.  
  12.     $tableheader = false;
  13.     $query = "SELECT * FROM <table_name>;";
  14.     $sth = $dbh->prepare($query);
  15.  
  16.     if(!$sth->execute()) {
  17.         die('Error');
  18.     }
  19.  
  20.     echo "<table>";
  21.  
  22.     while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
  23.         if($tableheader == false) {
  24.             echo '<tr>';
  25.             foreach($row as $key=>$value) {
  26.                 echo "<th>{$key}</th>";
  27.             }
  28.             echo '</tr>';
  29.             $tableheader = true;
  30.         }
  31.         echo "<tr>";
  32.         foreach($row as $value) {
  33.             echo "<td>{$value}</td>";
  34.         }
  35.         echo "</tr>";
  36.     }
  37.     echo "</table>";
  38.     ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top