In these tutorials, we will come to know how PHP can be connected to a database.
In a database, there can be multiple tables.
Each table can have multiple fields
How to create a database
We are considering that you already have phpmyadmin installed on your server.
Please go to phpmyadmin.
Click on “SQL”
Now write the following and press Go Again
Now we will create a table names “user”
So, we will write the following query.
create table users(
id int(11) NOT NULL AUTO_INCREMENT,
firstname varchar(255),
lastname varchar(255),
email varchar(255),
PRIMARY KEY (id)
);
How to insert data into the table(users)?
INSERT INTO users SET `firstname`=’RAM’, `lastname`=’SHAM’, `email`=’[email protected]’
How to update data of the table(users)?
Now we will update email address where id = 3
So we will write the following
UPDATE `users` SET `email` = ‘[email protected]’ WHERE `id` = 3;
To see all records from table.
Select * from tablename
OUTPUT WOULD BE LIKE THE FOLLOWING
To see selected fields from table
Select field1, field2 from tablename
Leave a comment