Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "consigna";
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- catch(PDOException $e){
- echo "Error: " . $e->getMessage();
- }
- $encabezadotabla = false;
- $query = "SELECT * FROM `empleados`";
- $stmt = $conn->prepare($query);
- if(!$stmt->execute()) {
- die('Error');
- }
- echo "<table>";
- while($fila = $stmt->fetch(PDO::FETCH_ASSOC)) {
- if($encabezadotabla == false) {
- echo '<tr>';
- foreach($fila as $clave=>$valor) {
- echo "<th>{$clave}</th>";
- }
- echo '</tr>';
- $encabezadotabla = true;
- }
- echo "<tr>";
- foreach($fila as $valor) {
- echo "<td>{$valor}</td>";
- }
- echo "</tr>";
- }
- echo "</table>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement