0

i am trying to store a XML file into MySQL DB. Here is my XML File-

<items>

 <item>

  <title>Google</title>

  <url>google.com</url>

 </item>

 <item>

  <title>Google Accounts</title>

  <url>accounts.google.com</url>

 </item>

</items> 

and here is my php file-

<?php
$xmlDoc = new DOMDocument();

$xmlDoc->load("items.xml");

$mysql_hostname = "localhost";

$mysql_user = "digifizz_voice";

$mysql_password = "admin";

$mysql_database = "digifizz_voicemail";

$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password)

or die("Opps some thing went wrong");

mysql_select_db($mysql_database, $bd)

or die("Opps some thing went wrong");

$x=$xmlDoc->getElementsByTagName('item');

for ($i=0; $i<=15000; $i++)

  {

  $title=$x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;

  $link=$x->item($i)->getElementsByTagName('url')->item(0)->childNodes->item(0)->nodeValue;

 $insert = "INSERT INTO items (title, url) VALUES ('$title', '$link')";

 $add_member = mysql_query($insert);

}

?>

But when i run this php on my web server i am gettinh this error-

Fatal error: Call to a member function getElementsByTagName() on a non-object in /home/xxxx/public_html/xxx/add.php on line 28

How can i resolve this error.

1 Answer 1

1

You need to some thing like

$dom->loadXML(file_get_contents("items.xml"));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.