camelCaseD
camelCaseD

Reputation: 2653

Convert xml to mysql using php?

Is there a way to convert an xml file to a mysql table as a sql statement using php?

I'm open to any PEAR packages you know of.

Upvotes: 2

Views: 7119

Answers (2)

AjayR
AjayR

Reputation: 4179

there are several packages available to read XML data in PHP (parsing XML). You can write simple code to insert the same in mysql with your custom fields.

I used ParseXml.class.php from phpclasses.org

The code should use like below.

require './ParseXml.class.php';

 $xml = new ParseXml();
 $xml->LoadFile("./test.xml");
 //$xml->LoadString($xmlString);
 //$xml->LoadRemote("http"//www.yourdomain.com/dir/filename.xml", 3);
 $dataArray = $xml->ToArray();

Upvotes: 1

Raptor
Raptor

Reputation: 54268

Actually, parsing XML to MySQL is a direct task and need a lot customization based on your XML structure. I suggest you to use SimpleXML to parse XML and insert into MySQL using PHP's MySQLi classes.

Upvotes: 3

Related Questions