Bagaimana cara memasukkan data JSON ke database MySQL menggunakan PHP?


<!DOCTYPE html>




    <script src=



    <link rel="stylesheet" href=


    <script src=




        .box {

            width: 750px;

            padding: 20px;

            background-color: #fff;

            border: 1px solid #ccc;

            border-radius: 5px;

            margin-top: 100px;






    <div class="container box">

        <h3 align="center">

            Geeks for Geeks Import JSON 

            data into database

        </h3><br />









            $connect = mysqli_connect("localhost", "root", "", "test"); 


            $query = '';

            $table_data = '';



            $filename = "college_subjects.json";



            $data = file_get_contents($filename); 



            $array = json_decode($data, true); 



            foreach($array as $row) {





                $query .= 

                "INSERT INTO student VALUES 

                ('".$row["name"]."', '".$row["gender"]."'

                '".$row["subject"]."'); "; 


                $table_data .= '









            if(mysqli_multi_query($connect, $query)) {

                echo '<h3>Inserted JSON Data</h3><br />';

                echo '

                <table class="table table-bordered">


                    <th width="45%">Name</th>

                    <th width="10%">Gender</th>

                    <th width="45%">Subject</th>



                echo $table_data;  

                echo '</table>';



        <br />





How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.