如何从数组中提取数据并存储到数据库
How To Extract Data From Array And Store To Database
编辑:
我决定彻底改变我对你们的表达方式。我正在使用亚马逊提供的脚本连接到 Alexa API 并获取一些信息。我的数据库中有一个 table,我正在从中提取行(通过 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
)
)
如您所见,每个 "objects" 对应于上面的代码,显示 Phone 号码、所有者姓名、电子邮件、街道、城市、州、邮政编码、国家/地区、链接分别计数和排名。
我需要做的是获取每个值并更新数据库中的该行。
编辑:
我决定彻底改变我对你们的表达方式。我正在使用亚马逊提供的脚本连接到 Alexa API 并获取一些信息。我的数据库中有一个 table,我正在从中提取行(通过 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
)
)
如您所见,每个 "objects" 对应于上面的代码,显示 Phone 号码、所有者姓名、电子邮件、街道、城市、州、邮政编码、国家/地区、链接分别计数和排名。
我需要做的是获取每个值并更新数据库中的该行。