Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>mysql example</title>
- </head>
- <body>
- <?php
- $servername = "localhost";
- $username = "student";
- $password = "";
- $dbname = "employees";
- // Create connection
- $conn = new mysqli ( $servername, $username, $password, $dbname );
- // Check connection
- if ($conn->connect_error) {
- die ( "Connection failed: " . $conn->connect_error );
- }
- $sql = "SELECT * from employees limit 10";
- $result = $conn->query ( $sql );
- echo "<table border='1' cellpadding='2' cellspacing='2'";
- echo "<tr><td>First Name</td><td>Second Name</td>";
- if ($result->num_rows > 0) {
- // output data of each row
- while ( $row = $result->fetch_assoc () ) {
- echo "<tr><td> " . $row ["first_name"] . "</td><td>" . $row ["last_name"] . "</td>";
- }
- } else {
- echo "0 results";
- }
- $conn->close ();
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement