Created
November 8, 2011 12:17
-
-
Save Fariah/1347614 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mshost = "localhost"; // Хост | |
$msuser = "root"; // Имя пользователя | |
$mspassword = ""; // Пароль | |
$dbname = "test_task_dev"; // Имя базы данных | |
$msconnect = mysql_connect($mshost, $msuser, $mspassword); | |
mysql_select_db($dbname, $msconnect); | |
$xml = new XMLReader(); | |
$xml->open("shop2.xml"); | |
function xml2assoc($xml) { | |
$tree = null; | |
while($xml->read()) | |
switch ($xml->nodeType) { | |
case XMLReader::END_ELEMENT: return $tree; | |
case XMLReader::ELEMENT: | |
$node = array('tag' => $xml->name, 'value' => $xml->isEmptyElement ? '' : xml2assoc($xml)); | |
if($xml->hasAttributes) | |
while($xml->moveToNextAttribute()) | |
$node['attributes'][$xml->name] = $xml->value; | |
$tree[] = $node; | |
break; | |
case XMLReader::TEXT: | |
case XMLReader::CDATA: | |
$tree .= $xml->value; | |
} | |
return $tree; | |
} | |
$xml_array = xml2assoc($xml); | |
$category = $xml_array[0]['value'][4]['value']; | |
$items = $xml_array[0]['value'][5]['value']; | |
//for ($i=0; $i<count($category); $i++) { | |
// $query = "INSERT INTO categories VALUES (" | |
// .$category[$i]['attributes']['id'].", " | |
// .$category[$i]['attributes']['parent_id'].", '" | |
// .$category[$i]['value']."')"; | |
// mysql_query($query); | |
//} | |
//for ($j=0; $j<count($items); $j++) { | |
// $sec_query = "INSERT INTO products VALUES (" | |
// .$items[$j]['attributes']['id'].", " | |
// .$items[$j]['value'][3]['value'].", '" | |
// .$items[$j]['value'][0]['value']."', " | |
// .$items[$j]['value'][2]['value'].", '" | |
// .$items[$j]['value'][4]['value']."')"; | |
// mysql_query($sec_query); | |
//} | |
mysql_close($msconnect); | |
?> | |
<html> | |
<head> | |
<title></title> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment