Answer the question
In order to leave comments, you need to log in
How to save parsed XML in MySQL?
There is an XML of the form:
<Langs>
<Lang>
<Cats>
<Cat>
<Items>
...
<Item ID="56"><Name>Имя 1</Name></Item>
<Item ID="55"><Name>Имя 2</Name></Item>
...
</Items>
</Cat>
</Cats>
</Lang>
</Langs>
<?
header("Content-Type: text/html; charset=utf-8");
$xml = simplexml_load_file('xml.php');
foreach ($xml->Langs->Lang->Cats->Cat->Items->Item as $Item) {
$Item['ID']; // извлекаем ID
$ID=$Item['ID'];
$Name=$Item->Name;
}
//Загружаем данные в БД
$user="login";
$password="pass";
$database="baza";
$dtable="table";
if ([email protected]_connect("localhost",$user,$password)){
mysql_select_db($database);
echo "База данных найдена!";
$query = mysql_query("SELECT COUNT(*) FROM $dtable WHERE ID='$ID'") or die(mysql_error());
$user = mysql_fetch_row($query);
$total = $user[0];
if ("$total" == 0) {
$sql = ("INSERT INTO $dtable (ID,Name) VALUES('$ID','$Name')");
$result = mysql_query($sql) or die("Error ".mysql_error());
} else {
echo 'ID существует!';
}
}
?>
Answer the question
In order to leave comments, you need to log in
$query = mysql_query("SELECT COUNT(*) FROM $dtable WHERE ID='$ID'")
...
if ("$total" == 0)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question