我正在學習php/sql/wamp,並在學習項目上遇到了很多麻煩...創建一個數據庫插入從PHP中的數據?
我有一個txt文件下面ive終於想通了加載到PHP,但我不知道如何處理創建將數據插入並執行查詢所需的數據庫sql ...是否有良好的鏈接或教程或示例代碼?下面是我的PHP和txt代碼
<?php
error_reporting(E_ERROR);
$header = '<?xml version="1.0" encoding="UTF-8"?>'."\n<datalist>";
$content = $header."\n".file_get_contents("data.txt")."\n</datalist>";
$ob = simplexml_load_string($content);
$json = json_encode($ob);
$array = json_decode($json, true);
$alldata = $array["pub"];
foreach ($alldata as $key => $value) { //access all data in loop
$id = $value["ID"];
$title = $value["title"];
$year = $value["year"];
$booktitle = $value["booktitle"];
$pages = $value["pages"];
$authors = implode(",", $value["authors"]["author"]);
//All process data can available here .run your sql query for insert.
}
?>
和我下面的txt文件..相同的格式,但對於數據的50MB
<pub>
<ID>0</ID>
<title>Regression Time Warping for Similarity Measure of Sequence</title>
<year>2004</year>
<booktitle>CIT</booktitle>
<pages>826-830</pages>
<authors>
<author>Hansheng Lei</author>
<author>Venu Govindaraju</author>
</authors>
</pub>
<pub>
<ID>1</ID>
<title>A Computational Model for Face Location Based on Cognitive Principles</title>
<year>1992</year>
<booktitle>AAAI</booktitle>
<pages>350-355</pages>
<authors>
<author>Venu Govindaraju</author>
<author>Sargur N. Srihari</author>
<author>David B. Sher</author>
</authors>
</pub>
$ ob = simplexml_load_string($ content); $ json = json_encode($ ob); $ array = json_decode($ json,true); 你爲什麼要加載到一個對象,然後json編碼它,然後解碼成一個數組?我是否錯過了爲什麼不從一開始就使用這個對象的原因? – skrilled
你建議$ array = $ ob? –
可能有成千上萬的關於MySQL的教程,以及如何在PHP中與這個在SO和交易過的Google員工中進行交互。 –