Professional Documents
Culture Documents
Phplabreport
Phplabreport
Phplabreport
SOURCE CODE:
<?php
$num=4;
$factorial=1;
for($x=$num;$x>=1;$x--)
{
$factorial=$factorial*$x;
}
echo"Factorial of $num is $factorial";
?>
OUTPUT:
2. WAP to check if 407 is armstrong or not.
SOURCE CODE:
<?php
$num=407;
$total=0;
$x=$num;
while($x!=0)
{
$rem=$x%10;
$total=$total+$rem*$rem*$rem;
$x=$x/10;
}
if($num==$total)
{
echo "Yes it is an Armstrong number";
}
else
{
echo "No it is not an armstrong number";
}
?>
OUTPUT:
3. Write a php code for the following:
a. Create a connection to MYSQL database.
OUTPUT:
<?php
echo"<br>";
$servername = "localhost";
$username = "root";
$password = "";
if(!$conn){
die("Unable to connect".mysqli_connect_error());
echo"Connected successfully";
?>
OUTPUT:
b. To create a database named texasplustwo.
SOURCE CODE:
<?php
echo"<br>";
$servername = "localhost";
$username = "root";
$password = "";
if(!$conn){
die("Unable to connect".mysqli_connect_error());
else{
echo"Connected successfully";
?>
c. Create a table named TexasStudent inside texasplustwo database. Include
the fields sno, name, address and grade.
SOURCE CODE:
<html>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database ="texasplustwo";
if(!$conn){
die("Unable to connect".mysqli_connect_error());
else{
echo"Connected successfully";
else{
?>
OUTPUT:
d. Insert a set of data in TexasStudent table.
SOURCE CODE:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database ="texasplustwo";
if(!$conn){
die("Unable to connect".mysqli_connect_error());
else{
echo"Connected successfully";
if ($result ){
}
else{
?>
</html>
OUTPUT:
e. Fetch the number of rows of TexasStudent table.
SOURCE CODE:
<html>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database ="texasplustwo";
if(!$conn){
die("Unable to connect".mysqli_connect_error());
else{
echo mysqli_num_rows($result);
?>
</html>
OUTPUT: