我似乎無法找到任何參考或示例(或者我沒有在正確的位置尋找)處理標籤的信息。更具體地說,使用PHP/PDO將標籤導入MySQL。我可以導入所有單值字段,但無法找到如何處理標籤,因爲每條記錄的標籤數量有所不同。處理這個問題的最好方法是什麼?如何使用PDO將json文件導入到MySQL時處理標籤?
香港專業教育學院建立我的數據庫是這樣的...
示例JSON數據...
{
"name": "Google",
"uri": "https://www.google.com",
"description": "The largest and most popular search engine in the world",
"tags": ["search", "web apps", "adwords"],
},
{
"name": "NFL",
"uri": "https://www.nfl.com",
"description": "The National Football League",
"tags": ["sports", "football"],
},
{
"name": "CNN",
"uri": "https://www.cnn.com",
"description": "Cable News Network",
"tags": [],
},
這裏是我使用導入的單一看重的PHP/PDO代碼字段...
$jsondata = file_get_contents('http://www.somewebsite/?format=json');
$data = json_decode($jsondata, true);
$stmt = $db->prepare("insert into bookmark values(?,?,?)");
foreach ($data as $row) {
$stmt->bindParam(1, $row['name']);
$stmt->bindParam(2, $row['uri']);
$stmt->bindParam(3, $row['description']);
$stmt->execute();
}
導入標籤?你打算創建一個標籤系統嗎? –