Wednesday, January 8, 2025

WT-I Assignment-5

 Assignment : 5 To study Files and Database (PHP-PostgreSQL)

 

SetA
Q1.Write a program to read one file and display the contents of the file with its size.

Solution :

<?php

$filenm=$_GET['t1'];

$fp=fopen($filenm,'r');

$fs=filesize($filenm);

echo fread($fp,$fs);

echo "filesize is".$fs;

?>

<!DOCTYPE html>

<html>

<head><title>Assign 5 set a q1</title></head>

<body>

<form name=f1 method=get action=http://192.168.100.252/ty2/ass5a2.php>

Enter file name: <input type=text name=t1>

<input type=submit value=Submit>

</form>

</body>

</html>

 

Q2. Consider the following entities and their relationships
Event (eno , title , date )
Committee ( cno , name, head , from_time ,to_time , status)
Event and Committee have many to many relationship. Write a script to accept title of event modify status committee as working.

Solution :-

<!DOCTYPE html>

<html>

<head><title>Assign 6 set a q1</title></head>

<body>

<form name=f1 method=get action=http://192.168.100.252/ty2/ass6a1.php>

Enter title: <input type=text name=t1>

<input type=submit value=Update>

</form>

</body>

</html>

<?php

$c=pg_connect("host=192.168.100.252 dbname=tydb3 user=ty3")

if(!$c)

echo 'not connected';

else

echo "done \n";

$e=$_GET['t1'];

$q=pg_query("update comm set status ='not done' where cno in (select cno from e_c where eno

in (select eno from event where title='0'));");

if(!$q)

echo "not updated";

else

echo "\n updated!";

?>



SetB
Q1) Write a program to read a flat file “item.dat”, which contains details of 5 different items such  as Item code, Item Name, unit sold, and Rate. Display the Bill in tabular format.

Solution:-

Item.dat

1 Book 10 15

2 Pen 5 10

3 Pencil 8 5

4 Bag 10 200

5 File 4 25

<!DOCTYPE html>

<html>

<body>

<?php

$filenm="item.dat";

$fp=fopen($filenm,'r');

?>

<centre>

<table border=2>

<?php

echo"<br><tr><th> item no</th><th> item name</th><th>unit sold</th><th>rate</th><th>total amt</th></tr></br>";

while(!feof($fp))

{

$x=explode(" ",fgets($fp));

$t=$x[2]*$x[3];

echo "<tr><td>$x[0]</td><td>$x[1]</td><td>$x[2]</td><td>$x[3]</td><td>$t</td></tr>";

}

?>

</table>

</centre>

</body>

</html>

 


Q2) Consider the following entities and their relationships
Student (Stud_id,name,class)
Competition (c_no,c_name,type)
Relationship between student and competition is many-many with attribute rank and year. Create a RDB in 3NF for the above and solve the following. Using above database write a script in PHP to accept a competition name from user and display information of student who has secured 1st rank in that competition.

Solution:-


 

SetC
Q 1. Write a menu driven program to perform various file operations. Accept filename from user.
a) Display type of file.
b) Display last access time of file
c) Display the size of file
d) Delete the file

Solution:-

<!DOCTYPE html>

<html>

<head><title>Assign 5 set b q1</title></head>

<body>

<table border=1>

<form name=f1 method=get action=http://192.168.100.252/ty2/ass5b1.php>

<tr><td>Enter file name: </td><td><input type=text name=t1></td></tr>

<tr><td><input type=radio name=r value=1></td><td>Display type of file</td></tr>

<tr><td><input type=radio name=r value=2></td><td>Display last access time of file</td></tr>

<tr><td><input type=radio name=r value=3></td><td>Display size of file</td></tr>

<tr><td><input type=radio name=r value=4></td><td>Delete the file</td></tr>

<tr><td colspan=2><input type=submit value=Submit></td></tr>

</form>

</table>

</body>

</html>

<?php

$f=$_GET['t1'];

$fp=fopen($f,"r");

$ch=$_GET['r'];//option name r

switch($ch)

{

case 1:

echo "Type of file: ".filetype($f);

break;

case 2:

echo "Last access time: ".date("F d Y H:i:s.",fileatime($f)); //day date year hr min seconds

break;

case 3:

echo "File size: ".filesize($f);

break;

case 4:

unlink($f);

if(!unlink($f))

{

echo "<br>Error deleting file";

}

else

{

echo "File deleted";

}

break;

}

?>


 

Q 2. Property (pno, description, area)
a. Owner (oname, address, phone)
b. An owner can have one or more properties, but a property belongs to exactly one owner. 

c. Accept owner name from the user. Write a PHP script which will display all properties which are own by that owner 

Solution:-


<!DOCTYPE html>

<html>

<head><title>Assign 6 set b q1</title></head>

<body>

<form name=f1 method=get action=http://192.168.100.252/ty2/ass6b1.php>

Enter name: <input type=text name=t1>

<input type=submit value=Show>

</form>

</body>

</html>

<?php

$c=pg_connect("host=192.168.100.252 dbname=tydb2 user=ty2");

if(!$c)

echo "not connected";

else

echo "done";

$t=$_GET['t1'];

$q=pg_query("select * from property where oname='".$t."';");

while($rs=pg_fetch_array($q))

{

echo "<br>Name: ".$rs[3]."<br>Property: ".$rs[1];

echo "<br>-----------";

}

?>



No comments:

Post a Comment