how to impoert json data into mysql database in js code example
Example 1: how to insert json data into mysql using php
<?php
$josndata = '{
"student":{ "name":"Harry", "country":"United State", "ContactNo":2545454 }
}';
$conn = new mysqli('localhost', 'username', 'password', 'databasename');
$sql = "INSERT INTO student_table ( name, jsondata )
VALUES ('Harry', '$josndata')";
if ($conn->query($sql) === TRUE) {
echo "Insert your JSON record successfully";
}
?>
Example 2: store json in mysql
CREATE DATABASE IF NOT EXISTS `e_store`
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
SET default_storage_engine = INNODB;
CREATE TABLE `e_store`.`brands`(
`id` INT UNSIGNED NOT NULL auto_increment ,
`name` VARCHAR(250) NOT NULL ,
PRIMARY KEY(`id`)
);
CREATE TABLE `e_store`.`categories`(
`id` INT UNSIGNED NOT NULL auto_increment ,
`name` VARCHAR(250) NOT NULL ,
PRIMARY KEY(`id`)
);