0% found this document useful (0 votes)
20 views18 pages

Update - 2022 - Sumona

The document discusses SQL queries and PHP code for performing CRUD operations on databases. It includes queries to select, insert, update, delete data from tables and code snippets for connecting to databases and displaying retrieved data in tables on webpages.

Uploaded by

bamir bamir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views18 pages

Update - 2022 - Sumona

The document discusses SQL queries and PHP code for performing CRUD operations on databases. It includes queries to select, insert, update, delete data from tables and code snippets for connecting to databases and displaying retrieved data in tables on webpages.

Uploaded by

bamir bamir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

2)i)

SELECT DISTINCT customer_name FROM depositor WHERE customer_name NOT IN (selec
t customer_name FROM borrower)

ii) delete From loan

Where amount between 5000 and 25000


iii) url-http://localhost/lab/bank/insert.php

<?php

$url='localhost:3306';

$username='root';

$password='';

$dbname='bank';

$conn=mysqli_connect($url,$username,$password, $dbname);

if(!$conn){

die('Could not Connect My Sql:' .mysql_error());

?>

<html>

<head>

<title>Add New Record in Mysql database</title>


</head>

<body>

<?php

if(isset($_POST['add'])) {

include_once 'db.php';

$customer_name = $_POST['customer_name'];

$customer_street = $_POST['customer_street'];

$customer_city = $_POST['customer_city'];

$sql="INSERT INTO customer"."(customer_name,customer_street,customer_city)"."VALUES


('$customer_name','$customer_street','$customer_city')";

if ($conn->query($sql) === TRUE) {

echo "New record created successfully";

} else {

echo "Error: " . $sql . "<br>" . $conn->error;

$conn->close();

} else {

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<p>

<label for="customer_name">Customer Name:</label>

<input type="text" name="customer_name" id="customerName">

</p>

<p>

<label for="customer_street">Customer Street:</label>

<input type="text" name="customer_street" id="customerStreet">

</p>

<p>
<label for="customer_city">Customer City:</label>

<input type="text" name="customer_city" id="customerCity">

</p>

<input type="submit" name="add" id="add" value="Add Customer">

</form>

<?php

?>

</body>

</html>

iv) <?php

$url='localhost:3306';

$username='root';

$password='';

$dbname='bank';

$conn=mysqli_connect($url,$username,$password, $dbname);

if(!$conn){

die('Could not Connect My Sql:' .mysql_error());

?>

<?php

include_once 'db.php';

$result = mysqli_query($conn,"SELECT * FROM customer");

?>

<!DOCTYPE html>

<html>

<head>
<title> Retrive data</title>

</head>

<body>

<?php

if (mysqli_num_rows($result) > 0) {

?>

<table>

<tr>

<td><span style="font-weight:bold">Customer Name</span></td>

<td><span style="font-weight:bold">Customer Street</span></td>

<td><span style="font-weight:bold">Customer City</span></td>

</tr>

<?php

$i=0;

while($row = mysqli_fetch_array($result)) {

?>

<tr>

<td><?php echo $row["customer_name"]; ?></td>

<td><?php echo $row["customer_street"]; ?></td>

<td><?php echo $row["customer_city"]; ?></td>

</tr>

<?php

$i++;

?>

</table>

<?php

else{
echo "No result found";

?>

</body>

</html>

4)i) SELECT cus.customer_name FROM customer cus


INNER JOIN depositor de ON de.customer_name = cus.customer_name
INNER JOIN borrower bo ON bo.customer_name = cus.customer_name;

ii) SELECT avg(balance) FROM account


GROUP BY branch_name;
iii) UPDATE account SET balance = balance - (balance *
IF(account_number IN (
SELECT de.account_number FROM depositor de
INNER JOIN borrower bo ON de.customer_name = bo.customer_name), 2, 3)
) / 100;

6)i) SELECT emp.employee_name, emp.employee_city, works.salary
FROM employee emp
INNER JOIN works works ON emp.employee_name = works.employee_name
WHERE works.company_name = 'pubali Bank Ltd'

ii) SELECT company_name, SUM(salary) from works GROUP BY company_name;
iii) http://localhost/lab/employee/insert.php

<?php

$url='localhost:3306';

$username='root';

$password='';

$dbname='employee';

$conn=mysqli_connect($url,$username,$password, $dbname);

if(!$conn){

die('Could not Connect My Sql:' .mysql_error());

?>

<html>

<head>
<title>Add New Record in Mysql database</title>

</head>

<body>

<?php

if(isset($_POST['add'])) {

include_once 'db.php';

$employee_name = $_POST['employee_name'];

$employee_street = $_POST['employee_street'];

$employee_city = $_POST['employee_city'];

$sql="INSERT INTO employee"."(employee_name, employee_street, employee_city)"."VALUES


('$employee_name','$employee_street','$employee_city')";

if ($conn->query($sql) === TRUE) {

echo "New record created successfully";

} else {

echo "Error: " . $sql . "<br>" . $conn->error;

$conn->close();

} else {

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<p>

<label for="employee_name">Employee Name:</label>

<input type="text" name="employee_name" id="employeeName">

</p>

<p>

<label for="employee_street">Employee Street:</label>

<input type="text" name="employee_street" id="employeeStreet">

</p>
<p>

<label for="employee_city">Employee City:</label>

<input type="text" name="employee_city" id="employeeCity">

</p>

<input type="submit" name="add" id="add" value="Add Employee">

</form>

<?php

?>

</body>

</html>

iv) <?php

$url='localhost:3306';

$username='root';

$password='';

$dbname='employee';

$conn=mysqli_connect($url,$username,$password, $dbname);

if(!$conn){

die('Could not Connect My Sql:' .mysql_error());

?>

<?php

include_once 'db.php';

$result = mysqli_query($conn,"SELECT * FROM employee");

?>

<!DOCTYPE html>
<html>

<head>

<title> Retrive data</title>

</head>

<body>

<?php

if (mysqli_num_rows($result) > 0) {

?>

<table>

<tr>

<td><span style="font-weight:bold">Employee Name</span></td>

<td><span style="font-weight:bold">Employee Street</span></td>

<td><span style="font-weight:bold">Employee City</span></td>

</tr>

<?php

$i=0;

while($row = mysqli_fetch_array($result)) {

?>

<tr>

<td><?php echo $row["employee_name"]; ?></td>

<td><?php echo $row["employee_street"]; ?></td>

<td><?php echo $row["employee_city"]; ?></td>

</tr>

<?php

$i++;

?>

</table>

<?php
}

else{

echo "No result found";

?>

</body>

</html>

5)Table creation-

CREATE TABLE books (

isbn int(50) NOT NULL,

title char(50) NOT NULL,

author varchar(255) NOT NULL,

publisher varchar(255) NOT NULL);

i) SELECT emp.name FROM employee emp, loan lo


WHERE emp.empno = lo.empno
AND lo.isbn IN (SELECT isbn FROM books WHERE publisher = 'xyz')
GROUP BY emp.name;
ii) SELECT emp.name FROM employee emp, loan lo
WHERE emp.empno = lo.empno
GROUP BY emp.name
HAVING count(lo.isbn) = (SELECT count(isbn) FROM books WHERE publisher = 'xyz');
iii)

SELECT publisher, name FROM employee e, books b, loan l


WHERE e.empno = l.empno
AND l.isbn = b.isbn
GROUP BY publisher, name
HAVING count(b.isbn) > 5;
1)i) INSERT INTO accident
(report_number, date, location)
VALUES
("AR2199", curdate(), "Gazipur");
ii) DELETE FROM car WHERE model = 'Toyota' AND license IN (SELECT ow.license FROM
owns ow, person p WHERE ow.driver_id = p.driver_id AND p.name = 'Simanto');

iii) SELECT count(distinct driver_id) FROM participate


WHERE report_number IN (SELECT ac.report_number FROM accident ac WHERE
year(ac.date) = '2018');
iV) UPDATE participate SET damage_amount = 30000
WHERE report_number = 'AR2197'
AND car = 'DHAKA2000';

You might also like