0

Hai every body,

i need help in
how to import this xml file into database using php
i tried this way
only one record only inserted,

any body plz help me.

$comment = $this->filepath."\\".$file ;

    $content = file_get_contents($plan);
// Break it into an array.... !
    $content_x = explode("<comment>", $content);
    reset($content_x);

        foreach($content_x as $item)
        {
        /* Reference Number */
        $id1 = strpos($item, '<personal_id>');
        $id2 = strpos($item, '</personal_id>');
        $id = $id2 - $id1;
        $pId = substr($item, $id1,  $id); 
 }



<?xml version="1.0"?>
-<comments>
-<co>
<personal_id>11</personal_id>
<message>create test says...</message>
<meetnewpeople_id>875</meetnewpeople_id>
<picture_id>875</picture_id>
<created_at>2013-01-09 07:36:15
</created_at>
<updated_at>2013-01-09 07:36:15
</updated_at>
</co>
<co>
<personal_id>11</personal_id>
<message>aaaaa</message>
<meetnewpeople_id>873</meetnewpeople_id>
<picture_id>873</picture_id>
<created_at>2013-01-09 07:48:59</created_at>
<updated_at>2013-01-09 07:48:59</updated_at>
</co>
<co>
<personal_id>11</personal_id>
<message>213232</message>
<meetnewpeople_id>875</meetnewpeople_id>
<picture_id>900</picture_id>
<created_at>2013-01-09 07:48:59</created_at>
<updated_at>2013-01-09 07:48:59</updated_at>
</co>

</comments>

plz help  me.
3
Contributors
2
Replies
14
Views
4 Years
Discussion Span
Last Post by Varadharaj_1
0

how to import xml data file into database using php?

You need a query to import the xml data into the database.

It should look like this:

INSERT INTO table (`personal_id`, `picture_id`, `meetnewpeople_id`, `message`, `created_at`, `updated_at`) VALUES ('$personal_id', '$picture_id', '$meetnewpeople_id', '$message', '$created_at', '$updated_at);
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.