Basic OOP PHP CRUD Operation Using MySQLi from Scratch

Today, We want to share with you Basic OOP PHP CRUD Operation Using MySQLi from Scratch.
In this post we will show you PHP – OOP CRUD Operation, hear for OOP PHP CRUD Operation Using MySQLi we will give you demo and example for implement.
In this post, we will learn about CRUD with MySQLi Prepared Statement using PHP with an example.

Basic OOP PHP CRUD Operation Using MySQLi from Scratch

There are the Following The simple About Basic OOP PHP CRUD Operation Using MySQLi from Scratch Full Information With Example and source code.

First of all You simple Create There are The folder and file structures list below.

  • Step 1: db.php
  • Step 2: index.php
  • Step 3: add.php
  • Step 4: edit.php
  • Step 5: delete.php
  • Step 6: style.css

CREATE TABLE in Databse

member table in the database to do the CRUD operations

tbl_member_details SQL query

CREATE TABLE IF NOT EXISTS `tbl_member_details` (
`id` int(11) NOT NULL,
  `member_area` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL
)

ALTER TABLE `tbl_member_details`
 ADD PRIMARY KEY (`id`);

ALTER TABLE `tbl_member_details`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=0;

Databse Connection String

db.php


Create using Prepared Statment

Read Records -> index.php

query($sql);	
$conn->close();		
?>


	
	Member


	
			
			num_records > 0) {		
					while($record = $result->fetch_assoc()) {
			?>
			<tr class="table-member-record" id="record-"> 
				
Member Area Member Name Member Email Action
<a href="edit.php?id=" class="link">OOP PHP CRUD Operation <a href="delete.php?id=" class="link">OOP PHP CRUD Operation

Add / Insert using Prepared Statement

add.php

prepare("INSERT INTO tbl_member_details (member_area,name,email) VALUES (?, ?, ?)");  
		$member_area=$_POST['member_area'];
		$name = $_POST['name'];
		$email= $_POST['email'];
		$sql->bind_param("sss", $member_area, $name, $email); 
		if($sql->execute()) {
			$success_status_success = "Member Added Successfully";
		} else {
			$status_error = "Problem in Adding New Record";
		}
		$sql->close();   
		$conn->close();
	} 
?>



	

.tbl-qa{border-spacing:0px;border-radius:5px;border:#6ab5b9 1px solid;}

  Add New Member 	



Add New Member

Delete using Prepared Statement

delete.php

prepare("DELETE  FROM tbl_member_details WHERE id=?");  
	$sql->bind_param("i", $_GET["id"]); 
	$sql->execute();
	$sql->close(); 
	$conn->close();
	header('location:index.php');		
?>

Update using Prepared Statement

edit.php

prepare("UPDATE tbl_member_details SET member_area=? , name=? , email=?  WHERE id=?");
		$member_area=$_POST['member_area'];
		$name = $_POST['name'];
		$email= $_POST['email'];
		$sql->bind_param("sssi",$member_area, $name, $email,$_GET["id"]);	
		if($sql->execute()) {
			$success_status_success = "Edited Successfully";
		} else {
			$status_error = "Problem in Editing Record";
		}

	}
	$sql = $conn->prepare("SELECT * FROM tbl_member_details WHERE id=?");
	$sql->bind_param("i",$_GET["id"]);			
	$sql->execute();
	$result = $sql->get_result();
	if ($result->num_records > 0) {		
		$record = $result->fetch_assoc();
	}
	$conn->close();
?>




.tbl-qa{border-spacing:0px;border-radius:5px;border:#6ab5b9 1px solid;}

member edit 



Member Edit
<input type="text" name="member_area" class="memberField" value="">
<input type="text" name="name" class="memberField" value="">
<input type="text" name="email" class="memberField" value="">

Custom

style.css

body{width:615px;font-family:arial;}
.tbl-qa{width: 100%;font-size:0.9em;background-color: #6ab5b9;border-spacing: 1px;border-radius: 5px;}
.tbl-qa th.table-member-header {padding: 5px;text-align: left;padding:12px;color:#3d3d3d;font-weight:normal;}
.tbl-qa .table-member-record td {padding:12px;background-color: #ebf6f7;vertical-align:top;}
.livebtn_url {padding: 20px 0px;text-align: right;}
.livebtn_url a{color: #428a8e;text-decoration: none;background-color: 3d3d3d;padding: 8px 20px;font-size: 0.8em;border: #428a8e 1px solid;    border-radius: 5px;}
.status_success {
	color: #FF0000;
	text-align: center;
	width: 100%;
}
.memberField {padding: 8px;border: #afced0 1px solid;border-radius: 5px;width: 250px;}
.member-form-submit {color: #3d3d3d;background-color: #4e7173;padding: 12px 50px;border: 0px;cursor: pointer;border-radius:5px;}
.status_success { padding:8px 12px;box-sizing: border-box;text-align: left;border-radius: 5px;}
.success {background-color: #c4e4c4;border: #9ac19a 1px solid;color: #4b8e4b;}
.error {background-color: #e4cbc4;border: #c19c9a 1px solid;color: #8e4e4b;}
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about 8 Simple Steps to Create CRUD Application in OOP PHP.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment