Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
13 views
43 pages
Dbms Compelete Manual
Uploaded by
parth92.6000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Download
Save
Save Dbms Compelete Manual For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
13 views
43 pages
Dbms Compelete Manual
Uploaded by
parth92.6000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Dbms Compelete Manual For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 43
Search
Fullscreen
// Output:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| customers |
| information_schema |
| mysql |
| performance_schema |
| persinsinfo |
| sakila |
| sys |
| teainds |
| world |
+--------------------+
9 rows in set (0.03 sec)
mysql> create database T3
-> ;
Query OK, 1 row affected (0.04 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| customers |
| information_schema |
| mysql |
| performance_schema |
| persinsinfo |
| sakila |
| sys |
| t3 |
| teainds |
| world |
+--------------------+
10 rows in set (0.00 sec)
mysql> use t3
Database changed
mysql> create table persons (id int, firstname varchar(255), lastname
varchar(255), city varchar(255), primary key (id));
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
+--------------+
| Tables_in_t3 |
+--------------+
| persons |
+--------------+
1 row in set (0.02 sec)
mysql> insert into persons values(1, 'NIlesh', 'sharma','Nashik');
Query OK, 1 row affected (0.01 sec)
mysql> insert into persons values(2, 'Anushka', 'Sharma','Mumbai');
Query OK, 1 row affected (0.00 sec)
mysql> insert into persons values(3, 'Gayatri', 'Jadhav','Chalisgaon');
Query OK, 1 row affected (0.01 sec)
mysq>linsert into persons values(3, 'Gayatri', 'Jadhav','Chalisgaon');
mysql> update persons set firstname='Aishwarya' where id=2;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from persons;
+----+-----------+----------+------------+
| id | firstname | lastname | city |
+----+-----------+----------+------------+
| 1 | NIlesh | sharma | Nashik |
| 2 | Aishwarya | Sharma | Mumbai |
| 3 | Gayatri | Jadhav | Chalisgaon |
+----+-----------+----------+------------+
3 rows in set (0.00 sec)
mysql> delete from persons where id=1;
Query OK, 1 row affected (0.00 sec)
mysql> alter table persons add emailid varchar(255);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> describe persons;
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| id | int | NO | PRI | NULL | |
| firstname | varchar(255) | YES | | NULL | |
| lastname | varchar(255) | YES | | NULL | |
| city | varchar(255) | YES | | NULL | |
| emailid | varchar(255) | YES | | NULL | |
+-----------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> alter table persons drop emailid;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table persons rename column id to rollno
-> ;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> describe persons;
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| rollno | int | NO | PRI | NULL | |
| firstname | varchar(255) | YES | | NULL | |
| lastname | varchar(255) | YES | | NULL | |
| city | varchar(255) | YES | | NULL | |
+-----------+--------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> truncate table persons;
Query OK, 0 rows affected (0.02 sec)
mysql> select * from persons;
Empty set (0.00 sec)
mysql> drop table persons;
Query OK, 0 rows affected (0.01 sec)
mysql> show tables;
Empty set (0.00 sec)
mysql> create table persons (id int, firstname varchar(255), lastname
varchar(255), city varchar(255), primary key (id));
Query OK, 0 rows affected (0.01 sec)
5 rows in set (0.00 sec)
mysql> alter table persons add emailid varchar(255);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> select * from persons;
+----+-----------+----------+------------+---------+
| id | firstname | lastname | city | emailid |
+----+-----------+----------+------------+---------+
| 1 | NIlesh | sharma | Nashik | NULL |
| 2 | Anushka | Sharma | Mumbai | NULL |
| 3 | Sandip | Kadus | Ahamadnagr | NULL |
| 4 | Dhanshree | Bhusare | Dhamori | NULL |
| 5 | Durgesh | Agrawal | Manmad | NULL |
+----+-----------+----------+------------+---------+
5 rows in set (0.00 sec)
mysql> update persons set emailid="
[email protected]
"
where id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from persons;
+----+-----------+----------+------------+----------------------------+
| id | firstname | lastname | city | emailid |
+----+-----------+----------+------------+----------------------------+
| 1 | NIlesh | sharma | Nashik |
[email protected]
|
| 2 | Anushka | Sharma | Mumbai | NULL |
| 3 | Sandip | Kadus | Ahamadnagr | NULL |
| 4 | Dhanshree | Bhusare | Dhamori | NULL |
| 5 | Durgesh | Agrawal | Manmad | NULL |
+----+-----------+----------+------------+----------------------------+
5 rows in set (0.00 sec)
mysql> select * from persons order by firstname
-> ;
+----+-----------+----------+------------+----------------------------+
| id | firstname | lastname | city | emailid |
+----+-----------+----------+------------+----------------------------+
| 2 | Anushka | Sharma | Mumbai | NULL |
| 4 | Dhanshree | Bhusare | Dhamori | NULL |
| 5 | Durgesh | Agrawal | Manmad | NULL |
| 1 | NIlesh | sharma | Nashik |
[email protected]
|
| 3 | Sandip | Kadus | Ahamadnagr | NULL |
+----+-----------+----------+------------+----------------------------+
5 rows in set (0.00 sec)
mysql> select * from persons order by firstname DESC
-> ;
+----+-----------+----------+------------+----------------------------+
| id | firstname | lastname | city | emailid |
+----+-----------+----------+------------+----------------------------+
| 3 | Sandip | Kadus | Ahamadnagr | NULL |
| 1 | NIlesh | sharma | Nashik |
[email protected]
|
| 5 | Durgesh | Agrawal | Manmad | NULL |
| 4 | Dhanshree | Bhusare | Dhamori | NULL |
| 2 | Anushka | Sharma | Mumbai | NULL |
+----+-----------+----------+------------+----------------------------+
5 rows in set (0.00 sec)
mysql> select * from persons order by firstname;
+----+-----------+----------+------------+----------------------------+
| id | firstname | lastname | city | emailid |
+----+-----------+----------+------------+----------------------------+
| 2 | Anushka | Sharma | Mumbai | NULL |
| 4 | Dhanshree | Bhusare | Dhamori | NULL |
| 5 | Durgesh | Agrawal | Manmad | NULL |
| 1 | NIlesh | sharma | Nashik |
[email protected]
|
| 3 | Sandip | Kadus | Ahamadnagr | NULL |
+----+-----------+----------+------------+----------------------------+
5 rows in set (0.00 sec)
mysql> select * from persons order by id DESC;
+----+-----------+----------+------------+----------------------------+
| id | firstname | lastname | city | emailid |
+----+-----------+----------+------------+----------------------------+
| 5 | Durgesh | Agrawal | Manmad | NULL |
| 4 | Dhanshree | Bhusare | Dhamori | NULL |
| 3 | Sandip | Kadus | Ahamadnagr | NULL |
| 2 | Anushka | Sharma | Mumbai | NULL |
| 1 | NIlesh | sharma | Nashik |
[email protected]
|
+----+-----------+----------+------------+----------------------------+
5 rows in set (0.00 sec)
mysql> create index i1 on persons (id, firstname);
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> help
mysql> help auto_increment
Name: 'AUTO_INCREMENT'
Description:
The AUTO_INCREMENT attribute can be used to generate a unique identity
for new rows:
Examples:
CREATE TABLE animals (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO animals (name) VALUES
('dog'),('cat'),('penguin'),
('lax'),('whale'),('ostrich');
SELECT * FROM animals;
mysql> alter table persons modify column id int AUTO_INCREMENT;
Query OK, 5 rows affected (1.51 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from persons;
+----+-----------+----------+------------+----------------------------+
| id | firstname | lastname | city | emailid |
+----+-----------+----------+------------+----------------------------+
| 1 | NIlesh | sharma | Nashik |
[email protected]
|
| 2 | Anushka | Sharma | Mumbai | NULL |
| 3 | Sandip | Kadus | Ahamadnagr | NULL |
| 4 | Dhanshree | Bhusare | Dhamori | NULL |
| 5 | Durgesh | Agrawal | Manmad | NULL |
+----+-----------+----------+------------+----------------------------+
5 rows in set (0.00 sec)
mysql> INSERT INTO Persons (FirstName,LastName)
values('rohit','sharma');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO Persons (FirstName,LastName)
values('rohit','sharma');
CREATE TABLE Orders (
OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES Persons(id)
);
mysql> create table persons (id int, firstname varchar(255), lastname
varchar(255), city varchar(255), primary key (id));
Query OK, 0 rows affected (0.02 sec)
mysql> insert into persons values(3, 'Gayatri', 'Jadhav','Chalisgaon');
Query OK, 1 row affected (0.00 sec)
mysql> select * from persons;
+----+-----------+----------+------------+
| id | firstname | lastname | city |
+----+-----------+----------+------------+
| 1 | NIlesh | sharma | Nashik |
| 2 | Anushka | Sharma | Mumbai |
| 3 | Gayatri | Jadhav | Chalisgaon |
+----+-----------+----------+------------+
3 rows in set (0.00 sec)
mysql> CREATE TABLE Orders (
-> OrderID int NOT NULL,
-> OrderNumber int NOT NULL,
-> PersonID int,
-> PRIMARY KEY (OrderID),
-> FOREIGN KEY (PersonID) REFERENCES Persons(id)
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> insert into orders values (1,22546,2);
mysql> select * from orders;
+---------+-------------+----------+
| OrderID | OrderNumber | PersonID |
+---------+-------------+----------+
| 1| 22546 | 2|
| 2| 22546 | 1|
| 3| 22546 | 3|
+---------+-------------+----------+
3 rows in set (0.00 sec)
mysql> select firstname , OrderID, OrderNumber from persons inner join
orders on persons.id=orders.personid
-> ;
+-----------+---------+-------------+
| firstname | OrderID | OrderNumber |
+-----------+---------+-------------+
| NIlesh | 2| 22546 |
| Anushka | 1| 12345 |
| Gayatri | 3| 53214 |
+-----------+---------+-------------+
3 rows in set (0.00 sec)
mysql> select firstname , OrderID, OrderNumber from persons inner join
orders on persons.id=orders.personid
-> ;
+-----------+---------+-------------+
| firstname | OrderID | OrderNumber |
+-----------+---------+-------------+
| NIlesh | 2| 22546 |
| Anushka | 1| 12345 |
| Gayatri | 3| 53214 |
+-----------+---------+-------------+
3 rows in set (0.00 sec)
mysql> select * from persons inner join orders on
persons.id=orders.personid;
+----+-----------+----------+------------+---------+-------------+----------+
| id | firstname | lastname | city | OrderID | OrderNumber | PersonID |
+----+-----------+----------+------------+---------+-------------+----------+
| 1 | NIlesh | sharma | Nashik | 2| 22546 | 1|
| 2 | Anushka | Sharma | Mumbai | 1| 12345 | 2|
| 3 | Gayatri | Jadhav | Chalisgaon | 3| 53214 | 3|
+----+-----------+----------+------------+---------+-------------+----------+
3 rows in set (0.00 sec)
mysql> create view v1 as select firstname, city from persons;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from v1;
+-----------+------------+
| firstname | city |
+-----------+------------+
| NIlesh | Nashik |
| Anushka | Mumbai |
| Gayatri | Chalisgaon |
+-----------+------------+
3 rows in set (0.00 sec)
//OUTPUT: SQL JOIN
mysql> use database_name
mysql> create table stud_info(Rno int, Name varchar(20), Address
varchar(20));
mysql> create table stud_marks(Rno int, DBMS int, TOC int, CN int);
mysql> insert into stud_info values (1,'Abhay','Nashik'), (2,'Sarika','Pune'),
(3,'Riya','Nashik'), (4,'Sachin','Manmad');
mysql> insert into stud_marks
values(1,50,60,55),(2,68,57,76),(3,45,76,70),(5,80,75,85);
mysql> select * from stud_info;
| Rno | Name | Address |
| 1 | Abhay | Nashik |
| 2 | Sarika | Pune |
| 3 | Riya | Nashik |
| 4 | Sachin | Manmad |
mysql> select * from stud_marks;
| Rno | DBMS | TOC | CN |
| 1 | 50 | 60 | 55 |
| 2 | 68 | 57 | 76 |
| 3 | 45 | 76 | 70 |
| 5 | 80 | 75 | 85 |
mysql> select stud_info.Rno, Name,DBMS,TOC,CN from stud_info inner
join stud_marks
on stud_info.Rno=stud_marks.Rno;
| Rno | Name | DBMS | TOC | CN |
| 1 | Abhay | 50 | 60 | 55 |
| 2 | Sarika | 68 | 57 | 76 |
| 3 | Riya | 45 | 76 | 70 |
3 rows in set (0.00 sec)
mysql> select stud_info.Rno, Name,DBMS,TOC,CN from stud_info left join
stud_marks on
stud_info.Rno=stud_marks.Rno;
| Rno | Name | DBMS | TOC | CN |
| 1 | Abhay | 50 | 60 | 55 |
| 2 | Sarika | 68 | 57 | 76 |
| 3 | Riya | 45 | 76 | 70 |
| 4 | Sachin | NULL | NULL | NULL |
4 rows in set (0.00 sec)
mysql> select stud_info.Rno, Name,DBMS,TOC,CN from stud_info right
join stud_marks
on stud_info.Rno=stud_marks.Rno;
| Rno | Name | DBMS | TOC | CN |
| 1 | Abhay | 50 | 60 | 55 |
| 2 | Sarika | 68 | 57 | 76 |
| 3 | Riya | 45 | 76 | 70 |
| NULL | NULL | 80 | 75 | 85 |
4 rows in set (0.00 sec)
mysql> select stud_marks.Rno, Name,DBMS,TOC,CN from stud_info right
join
stud_marks on stud_info.Rno=stud_marks.Rno;
| Rno | Name | DBMS | TOC | CN |
| 1 | Abhay | 50 | 60 | 55 |
| 2 | Sarika | 68 | 57 | 76 |
| 3 | Riya | 45 | 76 | 70 |
| 5 | NULL | 80 | 75 | 85 |
4 rows in set (0.00 sec)
//Sub queries.
// Create table EMP
mysql> create table Emp(Eid int, Ename varchar(20), City varchar(20),
Post
varchar(15),Salary int, deptno int);
//Insert 10 Rows in the same
mysql> insert into Emp values
(1,'John','Nashik','Clerk',5000,10),
(2,'Seema','Aurangabad','Developer',20000,20),
(3,'Amita','Nagar','Manager',70000,20),
(4,'Rakesh','Pune','Analyst',8000,10),
(5,'Samata','Nashik','Tester',20000,10),
(6,'Anita','Chandwad','Developer',30000,30),
(7,'Bhavika','Pune','Team-LR',50000,30),
(8,'Deepa','Mumbai','CEO',90000,10),
(9,'Nitin','Nagpur','Clerk',8000,30),
(10,'Pooja','Pune','Analyst',45000,20);
mysql> select * from Emp;
| Eid | Ename | City| Post| Salary | deptno |
| 1 | John | Nashik| Clerk| 5000 | 10 |
| 2 | Seema | Aurangabad | Developer | 20000 | 20 |
| 3 | Amita | Nagar| Manager | 70000 | 20 |
| 4 | Rakesh | Pune| Analyst | 8000 | 10 |
| 5 | Samata | Nashik| Tester | 20000 | 10 |
| 6 | Anita | Chandwad | Developer | 30000 | 30 |
| 7 | Bhavika | Pune| Team-LR | 50000 | 30 |
| 8 | Deepa | Mumbai| CEO| 90000 | 10 |
| 9 | Nitin | Nagpur| Clerk | 8000 | 30 |
| 10 | Pooja | Pune| Analyst | 45000 | 20 |
//Display the information of employees, paid more than ‘pooja' from emp
table
mysql> select * from Emp where salary>(select Salary from Emp where
Ename='Pooja');
+------+---------+--------+---------+--------+--------+
| Eid | Ename | City | Post | Salary | deptno |
+------+---------+--------+---------+--------+--------+
| 3 | Amita | Nagar | Manager | 70000 |20 |
| 7 | Bhavika | Pune | Team-LR | 50000 |30 |
| 8 | Deepa | Mumbai | CEO | 90000 | 10 |
//List the name of the employees, who live in the same city as of ‘Rakesh’
mysql> select * from Emp where City=(select City from Emp where
Ename='Rakesh');
+------+---------+------+---------+--------+--------+
| Eid | Ename | City | Post | Salary | deptno |
+------+---------+------+---------+--------+--------+
| 4 | Rakesh | Pune | Analyst | 8000 | 10 |
| 7 | Bhavika | Pune | Team-LR | 50000 | 30 |
| 10 | Pooja | Pune | Analyst | 45000 | 20 |
// Display the information of employees, paid greater salary than average
salary throughout the company.
mysql> select * from Emp where Salary>=(select avg(Salary) from Emp);
+------+---------+--------+---------+--------+--------+
| Eid | Ename | City | Post | Salary | deptno |
+------+---------+--------+---------+--------+--------+
| 3 | Amita | Nagar | Manager | 70000 | 20 |
| 7 | Bhavika | Pune | Team-LR | 50000 | 30 |
| 8 | Deepa | Mumbai | CEO| 90000 | 10 |
| 10 | Pooja | Pune | Analyst | 45000 | 20 |
// Display the information of employees, paid less salary than average
salary throughout the company.
mysql> select * from Emp where Salary<(select avg(Salary) from Emp);
+------+--------+------------+-----------+--------+--------+
| Eid | Ename | City
| Post
| Salary | deptno |
+------+--------+------------+-----------+--------+--------+
| 1 | John | Nashik | Clerk | 5000 | 10 |
| 2 | Seema | Aurangabad | Developer | 20000 | 20 |
| 4 | Rakesh | Pune| Analyst | 8000 |10 |
| 5 | Samata | Nashik| Tester | 20000 |10 |
| 6 | Anita | Chandwad | Developer | 30000 | 30 |
| 9 | Nitin | Nagpur | Clerk | 8000 | 30 |
//Display the information of employees having maximum salary in
company
mysql> select * from Emp where Salary=(select max(Salary) from Emp);
+------+-------+--------+------+--------+--------+
| Eid | Ename | City | Post | Salary | deptno |
+------+-------+--------+------+--------+--------+
| 8 | Deepa | Mumbai | CEO | 90000 | 10 |
//Display the information of employees having minimum salary in
company
mysql> select * from Emp where Salary=(select min(Salary) from Emp);
+------+-------+--------+-------+--------+--------+
| Eid | Ename | City | Post | Salary | deptno |
+------+-------+--------+-------+--------+--------+
| 1 | John | Nashik | Clerk | 5000 | 10 |
// IN Example- Display the employee name ,salary and department no of
those
employees whose salary is the minimum salary of that department.
mysql> SELECT Ename, salary, deptno FROM EMP WHERE salary IN
( SELECT MIN(salary) FROM emp GROUP BY deptno );
+--------+--------+--------+
| Ename | salary | deptno |
+--------+--------+--------+
| John | 5000 | 10 |
| Seema | 20000 | 20 |
| Rakesh | 8000 | 10 |
| Samata | 20000 | 10 |
| Nitin | 8000 | 30 |
// All Example- Display the employee name, salary and department no of
those employees whose salary is higher than all developers salary.
mysql> SELECT Ename, salary, deptno FROM EMP WHERE salary > All
( SELECT salary FROM emp Where post= 'Developer');
+---------+--------+--------+
| Ename | salary | deptno |
+---------+--------+--------+
| Amita | 70000 | 20 |
| Bhavika | 50000 | 30 |
| Deepa | 90000 | 10 |
| Pooja | 45000 | 20 |
+---------+--------+--------+
4 rows in set (0.00 sec)
// All Example- Display the employee name, salary and department no of
those employees whose salary is lower than all developers salary
mysql> SELECT Ename, salary, deptno FROM EMP WHERE salary < All
( SELECT salary FROM emp Where post= 'Developer'
+--------+--------+--------+
| Ename | salary | deptno |
+--------+--------+--------+
| John | 5000 | 10 |
| Rakesh | 8000 | 10 |
| Nitin | 8000 | 30 |
+--------+--------+--------+
3 rows in set (0.00 sec)
//Any Example- Display the employee name, salary and department no of
those employees whose salary is higher than salary of any developers
salary
mysql> SELECT Ename, salary, deptno FROM EMP WHERE salary >any
( SELECT salary FROM emp Where post= 'Developer')
+---------+--------+--------+
| Ename | salary | deptno |
+---------+--------+--------+
| Amita | 70000 |20 |
| Anita | 30000 |30 |
| Bhavika | 50000 |30 |
| Deepa | 90000 |10 |
| Pooja | 45000 |20 |
+---------+--------+--------+
5 rows in set (0.00 sec)
//Any Example- Display the employee name, salary and department no of
those employees whose salary is less than salary of developers salary.
mysql> SELECT Ename, salary, deptno FROM EMP WHERE salary <any
( SELECT salary FROM emp Where post= 'Developer')
+--------+--------+--------+
| Ename | salary | deptno |
+--------+--------+--------+
| John | 5000 | 10 |
| Seema | 20000 | 20 |
| Rakesh | 8000 | 10 |
| Samata | 20000 | 10 |
| Nitin | 8000 | 30 |
+--------+--------+--------+
//Output:
> show dbs
admin (empty)
local 0.078GB
> use admin
switched to db admin
> db
admin
> db.dropDatabase()
{ "dropped" : "admin", "ok" : 1 }
> db.createCollection('stud')
{ "ok" : 1 }
> show collections
stud
system.indexes
> db.emp.insert({rno:1,name:'Bhavana'})
WriteResult({ "nInserted" : 1 })
> db.emp.insert({name:'Amit',rno:2})
WriteResult({ "nInserted" : 1 })
> db.emp.insert({rno:3, email_id:'
[email protected]
'})
WriteResult({ "nInserted" : 1 })
> db.emp.find()
{ "_id" : ObjectId("6321a6f722267f027ba09604"), "rno" : 1, "name" :
"Bhavana" }
{ "_id" : ObjectId("6321a70922267f027ba09605"), "name" : "Amit", "rno" :
2}
{ "_id" : ObjectId("6321a71422267f027ba09606"), "rno" : 3, "email_id" :
"
[email protected]
" }
> db.emp.insert({_id:1,rno:4,name:"Akash"})
WriteResult({ "nInserted" : 1 })
> db.emp.find()
{ "_id" : ObjectId("6321a6f722267f027ba09604"), "rno" : 1, "name" :
"Bhavana" }
{ "_id" : ObjectId("6321a70922267f027ba09605"), "name" : "Amit", "rno" :
2}
{ "_id" : ObjectId("6321a71422267f027ba09606"), "rno" : 3, "email_id" :
"
[email protected]
" }
{ "_id" : 1, "rno" : 4, "name" : "Akash" }
> db.emp.insert({_id:1,rno:5,name:"Reena"})
WriteResult({
"nInserted" : 0,
"writeError" : {
"code" : 11000,
"errmsg" : "insertDocument :: caused by :: 11000 E11000
duplicate key error index: admin.emp.$_id_ dup key: { : 1.0 }"
}
})
> E11000 duplicate key error index: db1.emp.$_id_ dup key: { : 1.0 }
2022-09-14T15:36:35.402+0530 SyntaxError: Unexpected identifier
> db.emp.insert ([{rno:7,name:'a'},{rno:8,name:'b'},{rno:8,name:'c' } ] )
BulkWriteResult({
"writeErrors" : [ ],
"writeConcernErrors" : [ ],
"nInserted" : 3,
"nUpserted" : 0,
"nMatched" : 0,
"nModified" : 0,
"nRemoved" : 0,
"upserted" : [ ]
})
>
db.emp.insert({rno:10,name:'Ankit',hobbies:['singing','cricket','swimming']
,age:21})
WriteResult({ "nInserted" : 1 })
>
> db.emp.insert({rno:11, Name: {Fname:"Bhavana", Mname:"Amit",
Lname:"Khivsara"}})
WriteResult({ "nInserted" : 1 })
> db.emp.insert({rno:12, Name: "Janvi", Address:{Flat:501, Building:"Sai
Appart", area:"Tidke colony", city: "Nashik", state:"MH", pin:423101},
age:22})
WriteResult({ "nInserted" : 1 })
> db.emp.insert({rno:15, name:'Ravina', dob: ISODate("2019-09-14")})
WriteResult({ "nInserted" : 1 })
> db.emp.insert(
... {rno:17, name:"Ashika",
... date:Date(),
... awards:[{
... name:"Best c -Designer", year:2010, prize:"winner"},
... {name:"Wen site competition",year:2012,prize:"Runner-up"},
... {name:"Fashion show", year:2015,prize:"winner"
... }],
... city:"Nashik"})
WriteResult({ "nInserted" : 1 })
> db.emp.find().pretty()
{
"_id" : ObjectId("6321a6f722267f027ba09604"),
"rno" : 1,
"name" : "Bhavana"
}
{ "_id" : ObjectId("6321a70922267f027ba09605"), "name" : "Amit", "rno" :
2}
{
"_id" : ObjectId("6321a71422267f027ba09606"),
"rno" : 3,
"email_id" : "
[email protected]
"
}
{ "_id" : 1, "rno" : 4, "name" : "Akash" }
{ "_id" : ObjectId("6321a7b822267f027ba09607"), "rno" : 7, "name" : "a" }
{ "_id" : ObjectId("6321a7b822267f027ba09608"), "rno" : 8, "name" : "b" }
{ "_id" : ObjectId("6321a7b822267f027ba09609"), "rno" : 8, "name" : "c" }
{
"_id" : ObjectId("6321a7c422267f027ba0960a"),
"rno" : 10,
"name" : "Ankit",
"hobbies" : [
"singing",
"cricket",
"swimming"
],
"age" : 21
}
{
"_id" : ObjectId("6321a7d722267f027ba0960b"),
"rno" : 11,
"Name" : {
"Fname" : "Bhavana",
"Mname" : "Amit",
"Lname" : "Khivsara"
}
}
{
"_id" : ObjectId("6321a7e022267f027ba0960c"),
"rno" : 12,
"Name" : "Janvi",
"Address" : {
"Flat" : 501,
"Building" : "Sai Appart",
"area" : "Tidke colony",
"city" : "Nashik",
"state" : "MH",
"pin" : 423101
},
"age" : 22
}
{
"_id" : ObjectId("6321a7e922267f027ba0960d"),
"rno" : 15,
"name" : "Ravina",
"dob" : ISODate("2019-09-14T00:00:00Z")
}
{
"_id" : ObjectId("6321a7fe22267f027ba0960e"),
"rno" : 17,
"name" : "Ashika",
"date" : "Wed Sep 14 2022 15:37:58 GMT+0530 (IST)",
"awards" : [
{
"name" : "Best c -Designer",
"year" : 2010,
"prize" : "winner"
},
{
"name" : "Wen site competition",
"year" : 2012,
"prize" : "Runner-up"
},
{
"name" : "Fashion show",
"year" : 2015,
"prize" : "winner"
}
],
"city" : "Nashik"
}
> db.stud.insert([{rno:1, name:'Ashiti'}, {rno:2,name:'Savita'},
{rno:3,name:'Sagar'}, {rno:4,name:'Reena'},{rno:5,name:'Jivan'}])
BulkWriteResult({
"writeErrors" : [ ],
"writeConcernErrors" : [ ],
"nInserted" : 5,
"nUpserted" : 0,
"nMatched" : 0,
"nModified" : 0,
"nRemoved" : 0,
"upserted" : [ ]
})
> db.stud.find()
{ "_id" : ObjectId("6321a81a22267f027ba0960f"), "rno" : 1, "name" :
"Ashiti" }
{ "_id" : ObjectId("6321a81a22267f027ba09610"), "rno" : 2, "name" :
"Savita" }
{ "_id" : ObjectId("6321a81a22267f027ba09611"), "rno" : 3, "name" :
"Sagar" }
{ "_id" : ObjectId("6321a81a22267f027ba09612"), "rno" : 4, "name" :
"Reena" }
{ "_id" : ObjectId("6321a81a22267f027ba09613"), "rno" : 5, "name" :
"Jivan" }
> db.stud.find({rno:5})
{ "_id" : ObjectId("6321a81a22267f027ba09613"), "rno" : 5, "name" :
"Jivan" }
> db.stud.find({rno:5},{name:1})
{ "_id" : ObjectId("6321a81a22267f027ba09613"), "name" : "Jivan" }
> { "_id" : ObjectId("5d83af5aa44331f62bcd836d"), "name" : "Jivan" }
>
> db.stud.find({rno:5},{name:1,_id:0})
{ "name" : "Jivan" }
> { "name" : "Jivan" }
2022-09-14T15:39:21.534+0530 SyntaxError: Unexpected token :
> db.stud.find({rno:5},{name:1,_id:0})
{ "name" : "Jivan" }
> { "name" : "Jivan" }
2022-09-14T15:40:35.559+0530 SyntaxError: Unexpected token :
> db.stud.find({rno:4},{name:,id:0}){"name":"Akash"}
2022-09-14T15:41:37.704+0530 SyntaxError: Unexpected token ,
> db.stud.find({},{name:1,_id:0})
{ "name" : "Ashiti" }
{ "name" : "Savita" }
{ "name" : "Sagar" }
{ "name" : "Reena" }
{ "name" : "Jivan" }
> { "name" : "Ashiti" }
> db.stud.find({rno:{$gt:2}})
{ "_id" : ObjectId("6321a81a22267f027ba09611"), "rno" : 3, "name" :
"Sagar" }
{ "_id" : ObjectId("6321a81a22267f027ba09612"), "rno" : 4, "name" :
"Reena" }
{ "_id" : ObjectId("6321a81a22267f027ba09613"), "rno" : 5, "name" :
"Jivan" }
> db.stud.find({rno:{$lte:2}})
{ "_id" : ObjectId("6321a81a22267f027ba0960f"), "rno" : 1, "name" :
"Ashiti" }
{ "_id" : ObjectId("6321a81a22267f027ba09610"), "rno" : 2, "name" :
"Savita" }
> db.stud.find({rno:{$ne:2}})
{ "_id" : ObjectId("6321a81a22267f027ba0960f"), "rno" : 1, "name" :
"Ashiti" }
{ "_id" : ObjectId("6321a81a22267f027ba09611"), "rno" : 3, "name" :
"Sagar" }
{ "_id" : ObjectId("6321a81a22267f027ba09612"), "rno" : 4, "name" :
"Reena" }
{ "_id" : ObjectId("6321a81a22267f027ba09613"), "rno" : 5, "name" :
"Jivan" }
> db.stud.find({rno:{$in:[1,3,5]}})
{ "_id" : ObjectId("6321a81a22267f027ba0960f"), "rno" : 1, "name" :
"Ashiti" }
{ "_id" : ObjectId("6321a81a22267f027ba09611"), "rno" : 3, "name" :
"Sagar" }
{ "_id" : ObjectId("6321a81a22267f027ba09613"), "rno" : 5, "name" :
"Jivan" }
> db.stud.find().sort({rno:-1})
{ "_id" : ObjectId("6321a81a22267f027ba09613"), "rno" : 5, "name" :
"Jivan" }
{ "_id" : ObjectId("6321a81a22267f027ba09612"), "rno" : 4, "name" :
"Reena" }
{ "_id" : ObjectId("6321a81a22267f027ba09611"), "rno" : 3, "name" :
"Sagar" }
{ "_id" : ObjectId("6321a81a22267f027ba09610"), "rno" : 2, "name" :
"Savita" }
{ "_id" : ObjectId("6321a81a22267f027ba0960f"), "rno" : 1, "name" :
"Ashiti" }
> db.stud.find().sort({name:1})
{ "_id" : ObjectId("6321a81a22267f027ba0960f"), "rno" : 1, "name" :
"Ashiti" }
{ "_id" : ObjectId("6321a81a22267f027ba09613"), "rno" : 5, "name" :
"Jivan" }
{ "_id" : ObjectId("6321a81a22267f027ba09612"), "rno" : 4, "name" :
"Reena" }
{ "_id" : ObjectId("6321a81a22267f027ba09611"), "rno" : 3, "name" :
"Sagar" }
{ "_id" : ObjectId("6321a81a22267f027ba09610"), "rno" : 2, "name" :
"Savita" }
> db.stud.find({rno:{$gt:2}},{_id:0}).sort({rno:-1})
{ "rno" : 5, "name" : "Jivan" }
{ "rno" : 4, "name" : "Reena" }
{ "rno" : 3, "name" : "Sagar" }
> db.stud.find()
{ "_id" : ObjectId("6321a81a22267f027ba0960f"), "rno" : 1, "name" :
"Ashiti" }
{ "_id" : ObjectId("6321a81a22267f027ba09610"), "rno" : 2, "name" :
"Savita" }
{ "_id" : ObjectId("6321a81a22267f027ba09611"), "rno" : 3, "name" :
"Sagar" }
{ "_id" : ObjectId("6321a81a22267f027ba09612"), "rno" : 4, "name" :
"Reena" }
{ "_id" : ObjectId("6321a81a22267f027ba09613"), "rno" : 5, "name" :
"Jivan" }
> db.stud.distinct("rno")
[ 1, 2, 3, 4, 5 ]
> [ 1, 2, 3, 4, 5 ]
[ 1, 2, 3, 4, 5 ]
> db.stud.find().limit(2)
{ "_id" : ObjectId("6321a81a22267f027ba0960f"), "rno" : 1, "name" :
"Ashiti" }
{ "_id" : ObjectId("6321a81a22267f027ba09610"), "rno" : 2, "name" :
"Savita" }
> db.stud.find().skip(2)
{ "_id" : ObjectId("6321a81a22267f027ba09611"), "rno" : 3, "name" :
"Sagar" }
{ "_id" : ObjectId("6321a81a22267f027ba09612"), "rno" : 4, "name" :
"Reena" }
{ "_id" : ObjectId("6321a81a22267f027ba09613"), "rno" : 5, "name" :
"Jivan" }
> db.stud.find({name:/^A/})
{ "_id" : ObjectId("6321a81a22267f027ba0960f"), "rno" : 1, "name" :
"Ashiti" }
> db.stud.find({name:/i$/})
{ "_id" : ObjectId("6321a81a22267f027ba0960f"), "rno" : 1, "name" :
"Ashiti" }
> db.stud.find({name:/a/})
{ "_id" : ObjectId("6321a81a22267f027ba09610"), "rno" : 2, "name" :
"Savita" }
{ "_id" : ObjectId("6321a81a22267f027ba09611"), "rno" : 3, "name" :
"Sagar" }
{ "_id" : ObjectId("6321a81a22267f027ba09612"), "rno" : 4, "name" :
"Reena" }
{ "_id" : ObjectId("6321a81a22267f027ba09613"), "rno" : 5, "name" :
"Jivan" }
> db.stud.findOne()
{
"_id" : ObjectId("6321a81a22267f027ba0960f")
"rno" : 1,
"name" : "Ashiti"
}
> db.stud.find().count()
5
> db.stud.find({rno:{$gt:2}}).count()
3
> db.stud.insert({rno:8,address:{area:"College
Road",city:"Nashik",state:"MH"},name:"Arya"})
WriteResult({ "nInserted" : 1 })
> db.stud.find({"address.city":"Nashik"})
{ "_id" : ObjectId("6321a99722267f027ba09614"), "rno" : 8, "address" :
{ "area" : "College Road", "city" : "Nashik", "state" : "MH" }, "name" :
"Arya" }
> db.stud.insert({rno:9,hobbies:['singing','dancing','cricket']})
WriteResult({ "nInserted" : 1 })
> db.stud.find({hobbies:'dancing'})
{ "_id" : ObjectId("6321a9a822267f027ba09615"), "rno" : 9, "hobbies" :
[ "singing", "dancing", "cricket" ] }
> db.stud.update({rno:1},{$unset:{rno:1}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.stud.update({rno:2},{$set:{rno:22}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.stud.update({rno:50},{$set:{rno:55}},{upsert:true})
WriteResult({
"nMatched" : 0,
"nUpserted" : 1,
"nModified" : 0,
"_id" : ObjectId("6321a9c92cb29a58d3264181")
})
> //multi:true used to update in multiple documents
> db.stud.update({rno:5},{$set:{rno:15}},{multiple:true})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.stud.remove({rno:4})
WriteResult({ "nRemoved" : 1 })
> db.stud.remove({rno:4},1)
WriteResult({ "nRemoved" : 0 })
> db.stud.remove({})
WriteResult({ "nRemoved" : 7 })
//OUTPUT:
mysql> use neha;
Database changed
mysql> show tables;
+----------------+
| Tables_in_neha |
+----------------+
| borrower |
| fine |
| persons |
| student |
| student1 |
+----------------+
5 rows in set (0.03 sec)
mysql> select * from borrower;
+---------+-----------+--------------+------------+-------+
| Roll_no | Name | DateofoIssue | NameofBook | Satus |
+---------+-----------+--------------+------------+-------+
| 1 | Neha | 2017-06-25 | Java |I |
| 2 | Shantanu | 2017-07-10 | Networking | I |
| 3 | Nandini | 2017-05-22 | MySql |I |
| 4 | Vaishnavi | 2017-06-10 | DBMS |I |
| 5 | Aniket | 2017-07-05 | WT |I |
| 6 | Komal | 2017-06-30 | AI |I |
+---------+-----------+--------------+------------+-------+
6 rows in set (0.34 sec)
mysql> select * from fine;
Empty set (0.13 sec)
mysql>delimiter $
mysql>create procedure p1(In rno1 int(3),name1 varchar(30))
->begin
->Declare i_date date
->Declare diff int;
->select DateofoIssue into i_date from borrower where Roll_no=rno1 and
NameofBook=name1;
->SELECT DATEDIFF(CURDATE(),i_date)into diff;
->End;
->$
Query OK, 1 row affected (0.13 sec)
mysql> delimiter ;
mysql> call p1(1,'Java');
Query OK, 1 row affected (0.13 sec)
mysql>delimiter $
mysql>create procedure p1(In rno1 int(3),name1 varchar(30))
->begin
->Declare i_date date
->Declare diff int;
->select DateofoIssue into i_date from borrower where Roll_no=rno1 and
NameofBook=name1;
->SELECT DATEDIFF(CURDATE(),i_date)into diff;
->if diff>15 then
->Update borrower
->set satus='R'
->where Roll_no=rno1 and NameofBook=name1;
->End if;
->End;
->End;
->$
Query OK, 1 row affected (0.13 sec)
mysql> delimiter ;
mysql> call p1(1,'Java');
Query OK, 1 row affected (0.13 sec)
mysql> delimiter ;
mysql> call p1(2,'Networking');
Query OK, 1 row affected (0.13 sec)
mysql> select * from borrower;
+---------+-----------+--------------+------------+-------+
| Roll_no | Name | DateofoIssue | NameofBook | Satus |
+---------+-----------+--------------+------------+-------+
| 1 | Neha | 2017-06-25 | Java |R |
| 2 | Shantanu | 2017-07-10 | Networking | R |
| 3 | Nandini | 2017-05-22 | MySql |I |
| 4 | Vaishnavi | 2017-06-10 | DBMS |I |
| 5 | Aniket | 2017-07-05 | WT |I |
| 6 | Komal | 2017-06-30 | AI |I |
+---------+-----------+--------------+------------+-------+
6 rows in set (0.34 sec)
mysql>delimiter ;
mysql>create procedure p1(In rno1 int(3),name1 varchar(30))
->begin
->Declare i_date date
->Declare diff int;
->Declare fine_amt int;
->select DateofoIssue into i_date from borrower where Roll_no=rno1 and
name=name1;
->SELECT DATEDIFF(CURDATE(),i_date)into diff;
->if(diff>=15 and diff<=30)then
->SET fine_amt=diff*5;
->insert into fine values(rno1,CURDATE(),fine_amt);
->elseif(diff>30)then
->SET fine_amt=diff*50;
->insert into fine values(rno1,CURDATE(),fine_amt);
->End if;
->Update borrower set status='R' where Roll_no=rno1 and name=name1;
->End;
Query OK, 1 row affected (0.13 sec)
mysql> delimiter ;
mysql> call P3(1,'Java');
Query OK, 1 row affected (0.00 sec)
mysql> select * from fine;
Empty set (0.00 sec)
//code:
Example 1.
PL/SQL Block :
set autoprint on;
set serveroutput on;
set verify off;
declare cursor cu1 is
select Roll,Name from Student;
cursor cu2 is
select Roll from CompDep;
rno int;
nm varchar(20); rno2 int;
begin
open cu1; open cu2;
loop
fetch cu1 into rno,nm; fetch cu2 into rno2;
exit when cu1%found = false; if rno2 <> rno then
insert into CompDep values(rno,nm); end if;
end loop; close cu1; close cu2;
end;
Output:
SQL> create table CompDep(Roll int,Name varchar(20));
Table created.
SQL> create table Student(Roll int,Name varchar(20));
Table created.
SQL> insert into Student values(1,'a');
1 row created.
SQL> insert into Student values(2,'b');
1 row created.
SQL> insert into Student values(3,'c');
1 row created.
SQL> insert into Student values(4,'d');
1 row created.
SQL> insert into CompDep values(2,'b');
1 row created.
SQL> insert into CompDep values(5,'e');
1 row created.
SQL> insert into CompDep values(6,'f');
1 row created.
SQL> @C:\Users\sitrc\assign6.txt // call PL/SQL block code created above
OR
SQL> delimiter /
PL/SQL procedure successfully completed
SQL> select * from CompDep;
ROLL NAME
2b
e
f
a
b
c
d
7 rows selected.
—-----------------------------------------------------------------------------------------------------
Example 2.
mysql> use Vedant;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database
changed
mysql> createtable o_rollcall(roll_no int,name varchar(20),address
varchar(20));
Query OK, 0 rows affected (0.28 sec)
mysql> createtable n_rollcall(roll_no int,namevarchar(20),address
varchar(20));
Query OK, 0 rows affected (0.27 sec)
mysql> insert into o_rollcall values('1','Hitesh','Nandura');
Query OK, 1 row affected (0.05 sec)
mysql> insert into o_rollcall values('2','Piyush','MP');
Query OK, 1 row affected (0.06 sec)
mysql> insert into o_rollcall values('3','Ashley','Nsk');
Query OK, 1 row affected (0.05 sec)
mysql> insert into o_rollcall values('4','Kalpesh','Dhule');
Query OK, 1 row affected (0.05 sec)
mysql> insert into o_rollcall values('5','Abhi','Satara');
Query OK, 1 row affected (0.04 sec)
mysql> delimiter //
mysql> create procedure p3(in r1 int)
-> begin
-> declare r2 int;
-> declare exit_loop boolean;
-> declare c1 cursor for select roll_no from o_rollcall where roll_no>r1;
-> declare continue handler for not found set exit_loop=true;
-> open c1;
-> e_loop:loop
-> fetch c1 into r2;
-> if not exists(select * from n_rollcall where roll_no=r2)
-> then
-> insert into n_rollcall select * from o_rollcall where roll_no=r2;
-> end if;
-> if exit_loop
-> then
-> close c1;
-> leave e_loop;
-> end if;
-> end loop e_loop;-> end
-> //
Query OK, 0 rows affected (0.00 sec)
mysql> call p3(3);
-> //
Query OK, 0 rows affected (0.10 sec)
mysql> select * from n_rollcall;
-> //
+_______+_______+________+
| roll_no | name | address |
+_______+_______+________+
| 4 | Kalpesh | Dhule |
| 5 | Abhi | Satara |
+_______+_______+________+
2 rows in set (0.00 sec)
mysql> call p3(0);
-> //
Query OK, 0 rows affected (0.22 sec)
mysql> select * from n_rollcall;
-> //
+_______+_______+________+
| roll_no | name | address |
+_______+_______+________+
| 4 | Kalpesh | Dhule |
| 5 | Abhi | Satara |
| 1 | Hitesh | Nandura |
| 2 | Piyush | MP |
| 3 | Ashley | Nsk |
+_______+_______+________+
5 rows in set (0.00 sec)
mysql> insert into o_rollcall values('6','Patil','Kolhapur');
-> //
Query OK, 1 row affected (0.04 sec)
mysql> call p3(4);
-> //
Query OK, 0 rows affected (0.05 sec)
mysql> select * from n_rollcall;
-> //
+_______+_______+________+
| roll_no | name | address |
+_______+_______+________+
| 4 | Kalpesh | Dhule |
| 5 | Abhi | Satara |
| 1 | Hitesh | Nandura |
| 2 | Piyush | MP |
| 3 | Ashley | Nsk |
| 6 | Patil | Kolhapur |
+_______+_______+________+
6 rows in set (0.00 sec)
Code:
config1.php
<?php
define('DB_SERVER', 'localhost'); // Name of Serevr
define('DB_USERNAME', 'root'); // User of Database
define('DB_PASSWORD', '');
// Password
define('DB_DATABASE', 'ndd'); // Datanase Name
$db =
mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABAS
E);
// Check connection
if (!$db)
{
die("Connection failed: " . mysqli_connect_error());
}
//echo "Connected successfully";
?>
simple.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Record Form</title>
</head>
<center> <br> <br> <h3>Registration Form </h3>
<form name="myForm" action="<?php
method="post" enctype="multipart/form-data" >
echo($_SERVER["PHP_SELF"]);?>"
<table>
<tr> <td> <label for="firstName">First Name:</label> </td> <td>
<input
type="text" name="first_name" id="firstName"> </td> <td> <input
type="submit"
name="add" value="search"></td> </tr>
<tr> <td> <label for="lastName">Last Name:</label>
type="text" name="last_name" id="lastName" > </td> </tr>
</td>
<td> <input
<tr> <td> <label for="emailAddress">Email Address:</label> </td>
<td> <input
type="text" name="email" id="emailAddress" > </td></tr>
<tr> <td> <label> Upload Image </label> </td> <td> <input
type="file"
name="fileToUpload" id="fileToUpload"> </td></tr>
</table>
<table>
</tr><td><input type="submit" name="add" value="Submit"> </td>
<td><input
type="submit" name="add" value="delete"></td> <td><input
type="submit"
name="add"
value="update"></td>
<td><input
type="submit"
name="add"
value="display"></td></tr>
</table>
</form>
</center>
<br>
<?php
include("config1.php"); /* file contain the database name user name and
connection
details */
if(isset($_POST['add']))
{
$first_name = mysqli_real_escape_string($db,$_POST['first_name']);
$last_name = mysqli_real_escape_string($db,$_POST['last_name']);
$email = mysqli_real_escape_string($db,$_POST['email']);
$ch = mysqli_real_escape_string($db,$_POST['add']);
$file =
@addslashes(file_get_contents($_FILES["fileToUpload"]["tmp_name"]));
switch ($ch)
{
case "display":
$sql = "SELECT * from persons";
$result = mysqli_query($db, $sql);
?>
<center><h2> Registration </h2> </center>
<center> <table border="2">
<thead>
<tr>
<th>First Name</th>
<th>Last Name </th>
<th>Email Id</th>
<th>Photo</th>
</tr>
</thead>
<tbody>
<?php if (mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_assoc($result))
{
$im= '<img
src="data:image/jpeg;base64,'.base64_encode($row['image']).'"
height="100" width="100"/>'; //store image in varibale
echo
"<tr><td>{$row['first_name']}</td><td>{$row['last_name']}</td><td
>{$row['email']}<
/td><td> $im</td></tr>\n";
}
}
else
{
echo '<tr><td colspan="4">No Rows Returned</td></tr>';
} ?>
</tbody>
</table>
<?php
break;
case "Submit":
$sql = "INSERT INTO persons ". "(first_name,last_name,email,image) ". "
VALUES('$first_name','$last_name','$email','$file')";
$result = mysqli_query($db, $sql);
if ($result !=0)
{
echo "Recored is inserted : $result";
}
break;
case "delete":
$sql = " delete from persons where first_name='$first_name' ";
$result = mysqli_query($db, $sql);
if ($result !=0)
{
echo "Recored is delete : $first_name ";
}
//echo "delete button click ";
break;
case "update":
$sql = "update persons set first_name='$first_name',
last_name='$last_name',email='$email',image='$file' where
first_name='$first_name' ";
$result = mysqli_query($db, $sql);
if ($result !=0)
{
echo "Recored is update : $first_name ";
}
break;
case "search":
$sql = "SELECT * from persons where first_name= '".$first_name."'";
$result = mysqli_query($db, $sql) ;
?>
<center><h2> Registration </h2> </center>
<center> <table border="2">
<thead>
<tr>
<th>First Name</th>
<th>Last Name </th>
<th>Email Id</th>
<th>Photo</th>
</tr>
</thead>
<tbody>
<?php if (mysqli_num_rows($result)!==0)
{
while($row = mysqli_fetch_assoc($result))
{
$im= '<img
src="data:image/jpeg;base64,'.base64_encode($row['image']).'"
height="100" width="100"/>'; //store image in varibale
echo
"<tr><td>{$row['first_name']}</td><td>{$row['last_name']}</td><td
>{$row['email']}<
/td><td> $im</td></tr>\n";
//$im= '<img
src="data:image/jpeg;base64,'.base64_encode($row['image']).'"
height="10" width="50"/>';
}
}
else
{
echo '<tr><td colspan="4">No Record Found ! </td></tr>';
}
?>
</tbody>
</table>
<?php
break;
default:
echo $ch;
}
} ?>
</body>
</html> <!-- end of form -->
You might also like
Chatbot Presentation
PDF
0% (1)
Chatbot Presentation
21 pages
Filmora Activation
PDF
No ratings yet
Filmora Activation
3 pages
CoDeSys Version 3.5 First Steps Ver. 1
PDF
No ratings yet
CoDeSys Version 3.5 First Steps Ver. 1
74 pages
Microsoft Certified Azure Fundamentals AZ-900 Quick Reference Sheet
PDF
No ratings yet
Microsoft Certified Azure Fundamentals AZ-900 Quick Reference Sheet
45 pages
Mysql Queries
PDF
100% (1)
Mysql Queries
15 pages
Practical 2
PDF
No ratings yet
Practical 2
10 pages
DBMS Practical Code
PDF
No ratings yet
DBMS Practical Code
76 pages
Dbms Compelete Manual
PDF
No ratings yet
Dbms Compelete Manual
61 pages
DBMS Lab Record 2017-18 2.0
PDF
No ratings yet
DBMS Lab Record 2017-18 2.0
57 pages
Notes 1
PDF
No ratings yet
Notes 1
35 pages
SQL Docx
PDF
No ratings yet
SQL Docx
57 pages
Basic Mysql Operation
PDF
No ratings yet
Basic Mysql Operation
38 pages
Code Part
PDF
No ratings yet
Code Part
42 pages
SQL Queries - Madhu
PDF
No ratings yet
SQL Queries - Madhu
25 pages
Mysql Programs
PDF
No ratings yet
Mysql Programs
23 pages
Mysql Commands Notes
PDF
No ratings yet
Mysql Commands Notes
34 pages
Data Definition, Table Creation and Constraints
PDF
No ratings yet
Data Definition, Table Creation and Constraints
27 pages
20 5 25
PDF
No ratings yet
20 5 25
28 pages
Act 2
PDF
No ratings yet
Act 2
30 pages
SQL
PDF
No ratings yet
SQL
14 pages
Inventory Management
PDF
No ratings yet
Inventory Management
20 pages
DBMS Lab Record - Old
PDF
No ratings yet
DBMS Lab Record - Old
63 pages
SQL
PDF
No ratings yet
SQL
17 pages
Basic
PDF
No ratings yet
Basic
16 pages
Experiment No. 1 DBMS Creating A Database
PDF
No ratings yet
Experiment No. 1 DBMS Creating A Database
12 pages
My SQL
PDF
No ratings yet
My SQL
16 pages
Expt 4 C
PDF
No ratings yet
Expt 4 C
25 pages
Creating Database For Restaurant Final07
PDF
No ratings yet
Creating Database For Restaurant Final07
21 pages
Program 2 and 3
PDF
No ratings yet
Program 2 and 3
16 pages
Dbms Sachin
PDF
No ratings yet
Dbms Sachin
19 pages
Assignment 1A
PDF
No ratings yet
Assignment 1A
13 pages
91 Club
PDF
No ratings yet
91 Club
16 pages
Assignment 4
PDF
No ratings yet
Assignment 4
41 pages
DB
PDF
No ratings yet
DB
18 pages
Mysql Commands
PDF
No ratings yet
Mysql Commands
16 pages
DBMS Recap
PDF
No ratings yet
DBMS Recap
10 pages
Resturent Final
PDF
No ratings yet
Resturent Final
12 pages
Mysql Programs
PDF
No ratings yet
Mysql Programs
23 pages
Mysql
PDF
No ratings yet
Mysql
25 pages
Mysql: Dr. Hsiang-Fu Yu National Taipei University of Education Original by Qunfeng Dong
PDF
No ratings yet
Mysql: Dr. Hsiang-Fu Yu National Taipei University of Education Original by Qunfeng Dong
25 pages
Practical 4
PDF
No ratings yet
Practical 4
11 pages
DBMS Lab Ex 1& 2
PDF
No ratings yet
DBMS Lab Ex 1& 2
22 pages
DB pr2 Ass1
PDF
No ratings yet
DB pr2 Ass1
9 pages
Create Database
PDF
No ratings yet
Create Database
9 pages
My SQL: #To Show All Databses Availaible
PDF
No ratings yet
My SQL: #To Show All Databses Availaible
13 pages
Table Creation
PDF
No ratings yet
Table Creation
6 pages
Day 3 Dbms
PDF
No ratings yet
Day 3 Dbms
6 pages
copy
PDF
No ratings yet
copy
6 pages
Dbms Lab1 Exp
PDF
No ratings yet
Dbms Lab1 Exp
6 pages
Task 1
PDF
No ratings yet
Task 1
5 pages
Day2 Dbms Lab
PDF
No ratings yet
Day2 Dbms Lab
5 pages
OSI Model PDF
PDF
No ratings yet
OSI Model PDF
9 pages
SQL Class 12 Cbse
PDF
No ratings yet
SQL Class 12 Cbse
5 pages
Foreign
PDF
No ratings yet
Foreign
5 pages
SQL Commands (Command Prompt)
PDF
No ratings yet
SQL Commands (Command Prompt)
3 pages
DDL Commands
PDF
No ratings yet
DDL Commands
3 pages
Experiment 2
PDF
No ratings yet
Experiment 2
3 pages
SQL 1
PDF
No ratings yet
SQL 1
5 pages
Cse3a 80 Assgn02
PDF
No ratings yet
Cse3a 80 Assgn02
6 pages
MYSQL Day1
PDF
No ratings yet
MYSQL Day1
4 pages
Student - Teacher DB
PDF
No ratings yet
Student - Teacher DB
6 pages
Assign 5 SQL
PDF
No ratings yet
Assign 5 SQL
9 pages
Create
PDF
No ratings yet
Create
2 pages
Q 2
PDF
No ratings yet
Q 2
2 pages
Digital Bot (En)
PDF
No ratings yet
Digital Bot (En)
20 pages
Vendor Manual
PDF
No ratings yet
Vendor Manual
74 pages
Chapter 4 Enumeration
PDF
No ratings yet
Chapter 4 Enumeration
26 pages
Echograph 1090-1091 Avg Dac e 2006 06
PDF
No ratings yet
Echograph 1090-1091 Avg Dac e 2006 06
2 pages
Aprisa XE User Manual: September 2006
PDF
No ratings yet
Aprisa XE User Manual: September 2006
134 pages
Sentiment Analysis From Facebook Comments Using Au PDF
PDF
No ratings yet
Sentiment Analysis From Facebook Comments Using Au PDF
8 pages
Hospital Management System
PDF
No ratings yet
Hospital Management System
23 pages
Math1059 - Calculus
PDF
100% (1)
Math1059 - Calculus
98 pages
Professional Writing Skills Handout © Write It Well Academy
PDF
100% (1)
Professional Writing Skills Handout © Write It Well Academy
9 pages
How To Ace Jumbling Questions For RRB NTPC: Facebooktwitterwhatsappemailtelegram Google Bookmarksshare
PDF
No ratings yet
How To Ace Jumbling Questions For RRB NTPC: Facebooktwitterwhatsappemailtelegram Google Bookmarksshare
4 pages
Diamond 3 13 User Guide
PDF
No ratings yet
Diamond 3 13 User Guide
152 pages
Falcon Outdoor OI
PDF
No ratings yet
Falcon Outdoor OI
78 pages
2port-Efr Thu-6404
PDF
No ratings yet
2port-Efr Thu-6404
255 pages
Unit IV-storage Virtualization
PDF
No ratings yet
Unit IV-storage Virtualization
26 pages
Async Tasks With Apache Airflow
PDF
No ratings yet
Async Tasks With Apache Airflow
111 pages
Using Charles Proxy
PDF
No ratings yet
Using Charles Proxy
7 pages
Aoop-A CH
PDF
No ratings yet
Aoop-A CH
34 pages
Yan 2021 Fine Grained Motion Estimation For
PDF
No ratings yet
Yan 2021 Fine Grained Motion Estimation For
11 pages
SolarWinds CSFI Report
PDF
No ratings yet
SolarWinds CSFI Report
10 pages
3G Acceptance Doc SSV RAN 2014 - Phase5
PDF
No ratings yet
3G Acceptance Doc SSV RAN 2014 - Phase5
6 pages
Symmetric Polynomials
PDF
No ratings yet
Symmetric Polynomials
5 pages
HEC-RAS 507 Unsteady
PDF
No ratings yet
HEC-RAS 507 Unsteady
9 pages
Blockchain Based Framework For Software Development Using DevOps
PDF
No ratings yet
Blockchain Based Framework For Software Development Using DevOps
6 pages
1264 SNAP PID Module
PDF
No ratings yet
1264 SNAP PID Module
7 pages
Enterprise Network Services Design (IPv6)
PDF
No ratings yet
Enterprise Network Services Design (IPv6)
1 page
Apache Cassandra Administrator Associate - Exam Practice Tests
From Everand
Apache Cassandra Administrator Associate - Exam Practice Tests
Cristian Scutaru
No ratings yet