Skip to content

PHP code snippet – How to insert json data into mysql ?

<?php 

$josndata = '{
"student":{ "name":"Harry", "country":"United State", "ContactNo":2545454 }
}';  

// Database connection
$conn = new mysqli('localhost', 'username', 'password', 'databasename');

// Insert data Query
$sql = "INSERT INTO student_table ( name, jsondata )
VALUES ('Harry', '$josndata')";

if ($conn->query($sql) === TRUE) {
  echo "Insert your JSON record successfully";
} 
?>
See also  CSS code snippet - How to center a div vertically and horizontally?
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.