Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Data Base Connection</title>
- <link rel="stylesheet" type="text/css"
- href="CSS/Style1.CSS" title="style1">
- </head>
- <body>
- <h1 style="text-align:center">Connecting and reading from Database</h1>
- <?php
- //create connection variables
- $dbServer="localhost:3307";
- $dbUser="root";
- $dbPassword="";
- $dbName="SKDB2019";
- //create connection
- $conn=new mysqli($dbServer,$dbUser,$dbPassword,$dbName);
- if($conn->connect_error==true){
- die("Connection failed error ".$conn->$connect_error);
- }else{
- echo "<h3>Connection successful</h3>";
- }
- //sql statement to select all records
- $sql="SELECT * FROM STUDENT";
- //execute query
- $result = $conn->query($sql);
- echo"<table border='2'style='margin-left:auto;margin-right:auto;'>";
- echo"<th>ID</th><NAME</th><th>PHONE</th><th>CITY</th>";
- if($result->num_rows>0){
- while($row=$result->fetch_assoc()){
- echo"<tr><td>".$row["ID"]."</td>";
- echo"<td>".$row["Name"]."</td>";
- echo"<td>".$row["Phone"]."</td>";
- echo"<td>".$row["City"]."</td></tr>";
- }
- echo "</table>";
- }else{
- echo "<h3>No records in the table</h3>";
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement