BCA

WEB PROGRAMMING LAB

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6

PART B

PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10 PROGRAM 11 PROGRAM 12 PROGRAM 13 PROGRAM 14 PROGRAM 15 . . .

14. Write a program to connect the mysql-database and display connection status using PHP

OUTPUT:
ID NAME percentage
1 ram 77
2 ramya 88
3 kusuma 88

Instructions:
1. Create database in mysql using phpmyadmin page in wamp server
2. create student table with student(id,name,percentage, year)
3. use this details in php program
database name : mytestdata
user name : root
password : ***
table name : student
columns : id, name , percentage, year

program14.php

 



     < style >
table, th, td {
  border: 1px solid black;
}
 < /style >
 < ? php 
 
 $servername = "localhost";
$username = "root";
$password = "12345678";
$dbname = "mytestdb";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM student";
$result = $conn->query($sql);



if ($result->num_rows > 0) {
  // output data of each row
echo"<table  > <tr>    <th>ID</th>    <th>NAME</th>    <th>percentage</th>  </tr>";

  while($row = $result->fetch_assoc()) {

    echo "<tr><td>  " . $row["id"]. " </td><td> " . $row["name"]. "</td><td> " . $row["percentage"]. "</td> </tr>";

  }

 echo "</table>";
} else {
  echo "0 results";
}
$conn->close();
 
 
?>