0% found this document useful (0 votes)
91 views6 pages

Lab Session 11-B

This document provides instructions for connecting a MySQL database to a website using PHP. It discusses how to: 1) Connect to MySQL using PHP and create a database and table with fields. 2) Perform CRUD (create, read, update, delete) operations on the database using SQL queries in PHP. 3) Display data from the MySQL database on a web form and insert, update, and delete data from the database using a web form. 4) The final task is to write a PHP code to add, delete, and select employee information from the database.

Uploaded by

Sohema anwar
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)
91 views6 pages

Lab Session 11-B

This document provides instructions for connecting a MySQL database to a website using PHP. It discusses how to: 1) Connect to MySQL using PHP and create a database and table with fields. 2) Perform CRUD (create, read, update, delete) operations on the database using SQL queries in PHP. 3) Display data from the MySQL database on a web form and insert, update, and delete data from the database using a web form. 4) The final task is to write a PHP code to add, delete, and select employee information from the database.

Uploaded by

Sohema anwar
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/ 6

Web Engineering

Department of CS and SE

LAB SESSION 11-B: MYSQL DATABASE USING PHP

Objective
On completion of this lab, students will be able:

• To connect website with database.


• To perform CRUD operations in database using PHP .

PHP MYSQL
To connect MYSQL using PHP go to: http://localhost//phpmyadmin
Enter the username and password Give the database name in the field ‘create new database’.
 Click on create button.
 Create a new table in the database by giving a table name and number of fields then click on Go
 To give field name to the created table,
 Write the field name in the ‘field’ column,
 Select the data types for each fields, specify the length of each field then click on save to save the
fields and click on Go
 When clicked on Go the table field details will be displayed.
 To insert values in the field, go to insert and enter the values. Then click on Go.

1. SQL query for insert:


Syntax: Insert into table name values (‘value1’,’value2’,); Example: Insert into Login values (‘JOE’,
‘hello’);
To update the values, go to SQL and write the query to update the values and click on Go
2. SQL query for update:
Syntax: Update table_name set field_name=’value’ where field_name=’value’; Example: Update
Login set password=’abcde’ where name=’Radha’;
To delete the values, go to SQL and write the query to delete the values and click on go
3. SQL query for delete:
Syntax: Delete from table_name where field_name=’value’; Example: Delete from Login where
name=’Radha’;
The functions used to connect web form to the MYSQL database:
mysql_connect (): This function opens a link to a MySQL server on the specified host (in this case it's
localhost) along with a username (root) and password (q1w2e3r4/). The result of the connection is
stored in the variable $db.
mysql_select_db (): This tells PHP that any queries we make are against the mydb database.
Web Engineering
Department of CS and SE

mysql_query (): Using the database connection identifier, it sends a line of SQL to the MySQL server
to be processed. The results that are returned are stored in the variable $result.
mysql_result (): This is used to display the values of fields from our query. Using $result, we go to the
first row, which is numbered 0, and display the value of the specified fields. mysql_result ($result,
0,"position")): This should be treated as a string and printed.
Display the data from MYSQL database in Web Form.
Web Engineering
Department of CS and SE

Insert the data into MYSQL database using Web Form


Web Engineering
Department of CS and SE

Update the data present in MYSQL database using Web Form


Web Engineering
Department of CS and SE
Web Engineering
Department of CS and SE

Delete the data from MYSQL database using Web Form

Lab Task
1. Write a PHP code to Add employee information insert, delete, and select the data from
database.

You might also like