
CRUD stands for Create, Edit , Update and Delete. It’s major operation is store, view, modify and delete it. It mainly contain on a website to dynamic the website. A user who visit our website they can modify and retrieve the details from database.
In database, First we need to create a new database, the CREATE DATABASE statement is used to create a database in MySQL. A Create Database name must be unique.
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create database
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
CRUD OPERATIONS
- CREATE TABLE is used to create the new table in database and the table name must be unique.
For Example:
CREATE TABLE login_form(
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_name VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
email VARCHAR(50),
mobile_number INT(11) )
- SELECT data is used to select data from the table.
For Example:
SELECT user_name FROM login_form
- “ * “ used to select the all columns in table
For Example
SELECT * FROM login_form
- UPDATE data is used to update existing record into the table. If you remove the WHERE, all records will be Updated.The WHERE clause denote which record or records that should be Updated in the table.
For Example:
UPDATE login_form
SET column1=value1,column2 =value2,...
WHERE some_column=some_value
- DELETE data is used to delete record from the table. If you remove the WHERE, all records will be deleted. The WHERE clause denote which record or records that should be deleted in the table.
For Example:
DELETE FROM login_form
WHERE some_column = some_value
Learn more details about,
Magento for Beginners | Validation using Javascript