This is a simple program that pulls 1 record from a table called STUDENTS.
connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully
";
//The following SQL query pulls a single record(Zhang) from the table Student.
$sql = "SELECT id, name, dept_name, tot_cred FROM student where name='Zhang'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
$row = $result->fetch_assoc() ;
echo "Student ID: " . $row["id"]. "
";
echo "Name: " . $row["name"]. "
";
echo " Department:" . $row["dept_name"]. "
";
echo " Department:" . $row["tot_cred"]. "
";
//echo "Student ID: " . $row[1]. "
";
}
else {
echo "0 results";
}
$conn->close();
?>