المشاركات

عرض الرسائل ذات التصنيف PHP Insert JSON into MySQL

How to Insert Multiple JSON Data into MySQL Database in PHP

صورة
Hi! I have discussed about inserting json into mysql using php a while back. And I got several queries from readers about inserting multiple json objects into DB using the exact method. Inserting multiple objects involves multiple database transactions. There are less elegant ways to do this but using mysqli library’s Prepared Statement is the effective and secure way for this type of job. Prepared Statements has several advantages like utilizing fewer resources, preventing sql injection etc. I’ll show you here with an example, how to use mysqli prepared statement to insert multiple json data into mysql database in php. Create MySQL Database & Table First we need to create mysql database required for our example. Run this below sql command to create it. CREATE DATABASE `employee`; USE `employee`; CREATE TABLE IF NOT EXISTS `emp` ( `id` int(8) NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL, `gender` varchar(10) NOT NULL, `designation` varchar(30) NOT NULL, ...