Example 1: sql crud
INSERT INTO my_table (my_col) VALUES ('Hello');
SELECT my_col FROM my_table WHERE my_id = 33;
UPDATE my_table SET my_col = 'Holla' WHERE my_id= 33;
DELETE FROM my_table WHERE my_id = 33;
Example 2: crud applications means
Create , Read , Update , Delete
CRUD is an acronym for the four basic types of SQL commands: Create , Read , Update , Delete . Most applications have some kind of CRUD functionality, and we can assume that every programmer had to deal with CRUD at some point. A CRUD application is one that uses forms to get data into and out of a database.
Example 3: crud sql
CRUD is an acronym that stands for CREATE, READ, UPDATE, and DELETE.
These are the four most basic operations that can be performed with most traditional database systems and they are the backbone for interacting with any database.
Example 4: php oop crud database
<?php
class Customers
{
private $servername = "localhost";
private $username = "root";
private $password = "";
private $database = "blog_database";
public $con;
public function __construct()
{
$this->con = new mysqli($this->servername, $this->username,$this->password,$this->database);
if(mysqli_connect_error()) {
trigger_error("Failed to connect to MySQL: " . mysqli_connect_error());
}else{
return $this->con;
}
}
public function insertData($post)
{
$name = $this->con->real_escape_string($_POST['name']);
$email = $this->con->real_escape_string($_POST['email']);
$username = $this->con->real_escape_string($_POST['username']);
$password = $this->con->real_escape_string(md5($_POST['password']));
$query="INSERT INTO customers(name,email,username,password) VALUES('$name','$email','$username','$password')";
$sql = $this->con->query($query);
if ($sql==true) {
header("Location:index.php?msg1=insert");
}else{
echo "Registration failed try again!";
}
}
public function displayData()
{
$query = "SELECT * FROM customers";
$result = $this->con->query($query);
if ($result->num_rows > 0) {
$data = array();
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
return $data;
}else{
echo "No found records";
}
}
public function displyaRecordById($id)
{
$query = "SELECT * FROM customers WHERE id = '$id'";
$result = $this->con->query($query);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
return $row;
}else{
echo "Record not found";
}
}
public function updateRecord($postData)
{
$name = $this->con->real_escape_string($_POST['uname']);
$email = $this->con->real_escape_string($_POST['uemail']);
$username = $this->con->real_escape_string($_POST['upname']);
$id = $this->con->real_escape_string($_POST['id']);
if (!empty($id) && !empty($postData)) {
$query = "UPDATE customers SET name = '$name', email = '$email', username = '$username' WHERE id = '$id'";
$sql = $this->con->query($query);
if ($sql==true) {
header("Location:index.php?msg2=update");
}else{
echo "Registration updated failed try again!";
}
}
}
public function deleteRecord($id)
{
$query = "DELETE FROM customers WHERE id = '$id'";
$sql = $this->con->query($query);
if ($sql==true) {
header("Location:index.php?msg3=delete");
}else{
echo "Record does not delete try again";
}
}
}
?>
Example 5: crud operations
Create, Read, Update and Delete are the main operations of CRUD.
Example 6: php oop crud database
CREATE TABLE `customers` (
`id` int(100) NOT NULL,
`name` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`username` varchar(100) NOT NULL,
`password` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;