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

  Simple VueJS v-show and v-if Tutorial with example

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();		
?>


	
	<title>Member</title>


	<div class="livebtn_url"><a href="add.php">Add New</a></div>
	<table class="tbl-qa">	
		<thead>
			 <tr>
				<th class="table-member-header" width="20%">Member Area </th>
				<th class="table-member-header" width="20%">Member Name </th>
				<th class="table-member-header" width="20%">Member Email </th>
				<th class="table-member-header" width="20%" colspan="2">Action</th>
			  </tr>
		</thead>
		<tbody>		
			num_records > 0) {		
					while($record = $result->fetch_assoc()) {
			?>
			<tr class="table-member-record" id="record-"> 
				<td class="table-member-record"></td>
				<td class="table-member-record"></td>
				<td class="table-member-record"></td>
				<!-- action -->
				<td class="table-member-record" colspan="2"><a href="edit.php?id=" class="link"><img title="Edit" src="icon/edit.png" /></a> <a href="delete.php?id=" class="link"><img id="delete" title="Member Delete" src="icon/delete.png" /></a></td>
			</tr>
			
		</tbody>
	</table>


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;}

  <title>Add New Member</title> 	



<div class="success status_success"></div>

<div class="error status_success"></div>

<form name="frmMember" method="post" action="">
<div class="livebtn_url"><a href="index.php"> Back to List </a></div>
<table border="0" cellpadding="10" cellspacing="0" width="500" align="center" class="tbl-qa">
	<thead>
		<tr>
			<th colspan="2" class="table-member-header">Add New Member</th>
		</tr>
	</thead>
	<tbody>
		<tr class="table-member-record">
			<td><label>Member Area</label></td>
			<td></td>
		</tr>
		<tr class="table-member-record">
			<td><label>Name</label></td>
			<td></td>
		</tr>
		<tr class="table-member-record">
			<td><label>Email</label></td>
			<td></td>
		</tr>
		<tr class="table-member-record">
			<td colspan="2"></td>
		</tr>
	</tbody>
</table>
</form>


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;}

<title>member edit </title>



<div class="success status_success"></div>

<div class="error status_success"></div>

<form name="frmMember" method="post" action="">
<div class="livebtn_url"><a href="index.php">Back to List </a></div>
<table border="0" cellpadding="10" cellspacing="0" width="500" align="center" class="tbl-qa">
	<thead>
		<tr>
			<th colspan="2" class="table-member-header">Member Edit</th>
		</tr>
	</thead>
	<tbody>
		<tr class="table-member-record">
			<td><label>Member Area</label></td>
			<td><input type="text" name="member_area" class="memberField" value=""></td>
		</tr>
		<tr class="table-member-record">
			<td><label>Name</label></td>
			<td><input type="text" name="name" class="memberField" value=""></td>
		</tr>
		<tr class="table-member-record">
			<td><label>Email</label></td>
			<td><input type="text" name="email" class="memberField" value=""></td>
		</tr>
		<tr class="table-member-record">
			<td colspan="2"></td>
		</tr>
	</tbody>	
</table>
</form>


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 :

  PHP Laravel 7 Send Email Example Tutorial

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.