Php 如何使用JSON在MySQL数据库中插入大量数据

Php 如何使用JSON在MySQL数据库中插入大量数据,php,mysql,json,Php,Mysql,Json,我使用的是7个JSON文件,我试图一次插入95个冒号+50-100行 我的代码是这样的:我删除了大约6个JSON文件和其他行和列。这是我的代码的简短版本 <?php $requestsDone = 2; $maxRequests = 100; $currentnumber = 1; while ($requestsDone <= $maxRequests) { $response = file_get_contents("https://api.themoviedb.org

我使用的是7个JSON文件,我试图一次插入95个冒号+50-100行

我的代码是这样的:我删除了大约6个JSON文件和其他行和列。这是我的代码的简短版本

<?php
$requestsDone = 2;
$maxRequests = 100;
$currentnumber = 1;
while ($requestsDone <= $maxRequests) {

    $response = file_get_contents("https://api.themoviedb.org/3/movie/".$requestsDone."?api_key=522cexxxxxxxxxxxxx9ax34a");
    if ($response != FALSE) {
        $response = json_decode($response, true);
    }

if (  ($response["title"]) != ""   )
{

        $requestsDone++;

include 'admin/connectdb.php';

try {

    // prepare sql and bind parameters
    $stmt = $conn->prepare("INSERT INTO TABLE (title,image,money,tag1,tag2) 
    VALUES (:title, :image, :money,:tag1,:tag2)");
    $stmt->bindParam(':title', $title);
    $stmt->bindParam(':image', $image);
    $stmt->bindParam(':money', $money);
    $stmt->bindParam(':tag1', $tag1);
    $stmt->bindParam(':tag1', $tag2);

    // insert a row
    $movie_title = "".$response["title"]."";
if ( $response["image"] != ""        )
    $image = "".$response["image"]."";
if ( $response["money"] != ""        )
    $money = "".$response["money"]."";
if ( ($response["tag"][0]["name"]) != ""        )
    $tag1 = "".$response["tag"][0]["name"]."";
if ( ($response["tag"][1]["name"]) != ""        )
    $tag2 = "".$response["tag"][1]["name"]."";

    $stmt->execute();

    echo "New records created successfully ".$currentnumber++."  <br/>";
    }
catch(PDOException $e)
    {
    echo "Error: " . $e->getMessage();
    }
    $conn = null;

}

}
?>

我想你不能使用json以外的序列化?例如,您可以在csv上转换json吗?mySQL可以添加一个非常大的csv文件(它只是一个文本文件),我对csv一无所知。我可以使用3个选项:ext curl、pecl/httpv1、pecl/httpv2我应该使用@XenofexsTip:This
$image=“”.$response[“image”]。”
$image=$response[“image”]相同json只是文本。您不能在MySQL中添加非常大的文本。这不是个好主意。你能在你的代码中添加这一行吗(在json_解码之后),并将结果添加到你的问题中<代码>回显“”,打印($response,true),“
{"adult":false,"backdrop_path":"/87hTDiay2N2qWyX4Ds7ybXi9h8I.jpg","belongs_to_collection":null,"budget":63000000,"genres":[{"id":18,"name":"Drama"}],"homepage":"http://www.foxmovies.com/movies/fight-club","id":550,"imdb_id":"tt0137523","original_language":"en","original_title":"Fight Club","overview":"A ticking-time-bomb insomniac and a slippery soap salesman channel primal male aggression into a shocking new form of therapy. Their concept catches on, with underground \"fight clubs\" forming in every town, until an eccentric gets in the way and ignites an out-of-control spiral toward oblivion.","popularity":9.765478999999999,"poster_path":"/adw6Lq9FiC9zjYEpOqfq03ituwp.jpg","production_companies":[{"name":"Regency Enterprises","id":508},{"name":"Fox 2000 Pictures","id":711},{"name":"Taurus Film","id":20555},{"name":"Linson Films","id":54050},{"name":"Atman Entertainment","id":54051},{"name":"Knickerbocker Films","id":54052}],"production_countries":[{"iso_3166_1":"DE","name":"Germany"},{"iso_3166_1":"US","name":"United States of America"}],"release_date":"1999-10-15","revenue":100853753,"runtime":139,"spoken_languages":[{"iso_639_1":"en","name":"English"}],"status":"Released","tagline":"How much can you know about yourself if you've never been in a fight?","title":"Fight Club","video":false,"vote_average":8.199999999999999,"vote_count":8047}