PHP MySQLi Insert Update Delete Query Builder

PHP MySQLi Insert Update Delete Query Builder

Today, We want to share with you PHP MySQLi Insert Update Delete Query Builder.In this post we will show you INSERT, UPDATE and DELETE with mysqli, hear for PHP OOPs dynamic insert update delete data in MySQLi we will give you demo and example for implement.In this post, we will learn about Create a Simple CRUD Database App: Connecting to MySQLi with PHP with an example.

PHP MySQLi Insert Update Delete Query Builder

There are the Following The simple About PHP MySQLi Insert Update Delete Query Builder Full Information With Example and source code.

As I will cover this Post with live Working example to develop Update Data in MySQL Database Table Using PHP with MySQLi, so the php MySQLi code for updating data in mysql database for this example is following below.

  PHP mysqli insert update delete for Dynemic query

Connect to Database

The PHP MySqli Simple two basic ways to connect to the database Like as a procedural and object oriented

$mysqli =  mysqli_connect('host','root','my_pwd','aisd');

$mysqli = new mysqli('host','root','my_pwd','aisd');

“object-oriented” Get Errors

connect_error) {
    die('Sorry, Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

?>

SELECT Multiple Records

PHP mysqli SELECT Multiple Records as Associative array

connect_error) {
    die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

$results = $mysqli->query("SELECT id, member_code, member_desc, reputations FROM members");

print '<table border="1">';
while($row = $results->fetch_assoc()) {
	print '<tr>';
    print '<td>'.$row["id"].'</td>';
	print '<td>'.$row["member_code"].'</td>';
	print '<td>'.$row["member_name"].'</td>';
	print '<td>'.$row["member_desc"].'</td>';
	print '<td>'.$row["reputations"].'</td>';
	print '</tr>';
}  
print '</table>';

$results->free();

$mysqli->close();
?>

PHP MySQLi SELECT Multiple Records as Array

fetch_array() : Function returns an array

connect_error) {
    die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

$results = $mysqli->query("SELECT id, member_code, member_desc, reputations FROM members");

print '<table>fetch_array()) {
	print '<tr>';
    print '<td>'.$row["id"].'</td>';
	print '<td>'.$row["member_code"].'</td>';
	print '<td>'.$row["member_name"].'</td>';
	print '<td>'.$row["member_desc"].'</td>';
	print '<td>'.$row["reputations"].'</td>';
	print '</tr>';

}   
print '</table>';
$results->free();

$mysqli->close();
?>

PHP MySQLi SELECT Multiple Records as Objects

connect_error) {
    die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

$results = $mysqli->query("SELECT id, member_code, member_desc, reputations FROM members");

print '<table border="1">';
while($row = $results->fetch_object()) {
	print '<tr>';
    print '<td>'.$row->id.'</td>';
	print '<td>'.$row->member_code.'</td>';
	print '<td>'.$row->member_name.'</td>';
	print '<td>'.$row->member_desc.'</td>';
	print '<td>'.$row->reputations.'</td>';
	print '</tr>';
}  

print '</table>';

$mysqli->close();
?>

SELECT Single value

connect_error) {
    die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

$member_name = $mysqli->query("SELECT member_name FROM members WHERE id = 1")->fetch_object()->member_name; 
print $member_name; //output value

$mysqli->close();
?>

PHP MySQLi SELECT COUNT Total records of a table

connect_error) {
    die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

$results = $mysqli->query("SELECT COUNT(*) FROM members");
$get_total_rows = $results->fetch_row(); //hold total records in variable

$mysqli->close();
?>

PHP MySQLi SELECT Using Prepared Statements

$search_member = "MD1001"; //member id

$query = "SELECT id, member_code, member_desc, reputations FROM members WHERE member_code=?";
$statement = $mysqli->prepare($query);

$statement->bind_param('s', $search_member);

$statement->execute();

$statement->bind_result($id, $member_code, $member_desc, $reputations);

print '<table border="1">';

while($statement->fetch()) {
	print '<tr>';
    print '<td>'.$id.'</td>';
	print '<td>'.$member_code.'</td>';
	print '<td>'.$member_desc.'</td>';
	print '<td>'.$reputations.'</td>';
	print '</tr>';

}   
print '</table>';

//close connection
$statement->close();

PHP MySQLi Insert or Update if record already exists

Simple Insert or Update if record already exists Query

$id = 0; 
$member_code = "M98256";
$member_name = "Krunal Sisodiya";
$member_desc = "Best friends To Parag shukla from DSP study Points";
$reputations = "1000";

$query = "INSERT INTO members (id, member_code, member_name, member_desc, reputations) 
			VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE member_code=?, member_name=?, member_desc=?, reputations=?";

$statement = $mysqli->prepare($query);

$statement->bind_param('dsssdsssd', $id, $member_code, $member_name, $member_desc, $reputations, //insert vars
									 $member_code, $member_name, $member_desc, $reputations); //update vars

$statement->execute();

Angular 6 CRUD Operations Application Tutorials

Read :

  vue.js check uncheck all checkboxes Example

Summary

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

I hope you get an idea about PHP MySQLi Insert Update Delete Query Builder.
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.