Blog Introductions

In this  blog contains tutorials about  HTML Tutorials, Python Tutorials, CSS Tutorials, How to, PHP Tutorials, Java Tutorials, C++ Tutorials, Tutorials,  Examples, Source code,Learning,
Tips and Software development  services. Php with mysql database  | php mysql crud operation | Php tutorials Bestitworriors


Php with mysql database 

Php tutorials




Php with mysql database  | php mysql crud operation | Php tutorials Bestitworriors -Mysql is most popular database which use with php and easy to work with it.Mysql database used on website for holding the website data.We can perform various operation on php with mysql database we can insert data into the database and select data from database and show into out website and we can update data into the database and we can delete data from database.we will perform all these function with php mysql database.


Some Key Points of Mysql database



  1. Mysql hold data for a website
  2. First we make connection of php with the database
  3. After making connection we get the database object
  4. Now we will write query of insert function and send data
  5. Now we will write query of Select function and get data
  6. Now we will write query of Update function and send new data
  7. Now we will write query of Delete function and Delete data
  8. Data base can hold all kind of information like images,videos and text and files

Code





<?php

// Connection
$servername = "localhost";
$username = "username";
$password = "";
$dbname = "StudentRecord";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}


// Insert Data


$sql = "INSERT INTO Students (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}






//SELECT Data


$sql = "SELECT id, firstname, lastname FROM Students";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}

// Delete Data



$sql = "DELETE FROM Students WHERE id=3";

if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}



// Update Data



$sql = "UPDATE Students SET lastname='Doe' WHERE id=2";

if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}




$conn->close();
?>










I hope You really enjoyed this blog . I try my best to make every thing is easy and helpfull to provide to public .You will get more blog about the Programing project and code . Thanks for visiting my blog if you have any querry related to this you can comment here i will try my best to response you back about  Php with mysql database  | php mysql crud operation | Php tutorials Bestitworriors