簡體   English   中英

如何從數組中提取數據並將其存儲到數據庫

[英]How To Extract Data From Array And Store To Database

編輯:

我決定徹底改變我對你們的看法。 我正在使用Amazon提供的腳本來連接到Alexa API並獲取一些信息。 我的數據庫中有一個表,該表用於(通過URL)從中提取行,並使用此腳本嘗試使用此收集的信息更新當前空白的某些列。

以下示例顯示了我從http://google.com獲得的結果

我希望我已經說出了這個權利,並且不要太困惑。

如下代碼:

public static function parseResponse($response) {
    $xml = new SimpleXMLElement($response,null,false,
                                'http://awis.amazonaws.com/doc/2005-07-11');
    if($xml->count() && $xml->Response->UrlInfoResult->Alexa->count()) {
        $info = $xml->Response->UrlInfoResult->Alexa;
        $nice_array = array(
            'Phone Number'   => $info->ContactInfo->PhoneNumbers->PhoneNumber,
            'Owner Name'     => $info->ContactInfo->OwnerName,
            'Email'          => $info->ContactInfo->Email,
            'Street'         => $info->ContactInfo->PhysicalAddress->Streets->Street,
            'City'           => $info->ContactInfo->PhysicalAddress->City,
            'State'          => $info->ContactInfo->PhysicalAddress->State,
            'Postal Code'    => $info->ContactInfo->PhysicalAddress->PostalCode,
            'Country'        => $info->ContactInfo->PhysicalAddress->Country,
            'Links In Count' => $info->ContentData->LinksInCount,
            'Rank'           => $info->TrafficData->Rank
        );
    }
    echo '<pre>';
    print_r(array_values($nice_array));
    echo '</pre>';
}

將輸出以下內容:

Array
(
    [0] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [1] => SimpleXMLElement Object
        (
            [0] => aa
        )

    [2] => SimpleXMLElement Object
        (
            [0] => dns-admin@google.com
        )

    [3] => SimpleXMLElement Object
        (
            [0] => aa
        )

    [4] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [5] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [6] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [7] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [8] => SimpleXMLElement Object
        (
            [0] => 3555997
        )

    [9] => SimpleXMLElement Object
        (
            [0] => 1
        )

)

如您所見,這些“對象”均與上面的代碼相對應,分別顯示電話號碼,所有者名稱,電子郵件,街道,城市,州,郵政編碼,國家/地區,計數鏈接和排名。

我需要做的是獲取每個值並更新數據庫中的該行。

讓PHP為您完成工作;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM