Ankündigung

Einklappen
Keine Ankündigung bisher.

Feed in Datenbank eintragen (Formate: json, php serialized, xml)

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Feed in Datenbank eintragen (Formate: json, php serialized, xml)

    Hallo miteinander,

    ich habe eine kurze Anfänger Frage bezüglich der Speicherung von Feedinhalten in einer MySQL Datenbank.
    Es handelt sich dabei um einen Fußballfeed der in drei Formaten vorliegt.

    Der Feed im Format "php serialized" sieht folgendermaßen aus:

    Code:
    a:2:{s:11:"total-count";i:56;s:5:"items";a:20:{i:0;a:6:{s:2:"id";s:32:"18b4511935774dabc6ecfcf3e3561ad0";s:16:"timestamp_starts";i:1276264800;s:6:"status";s:8:"finished";s:5:"score";s:5:"1 - 1";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:12:"South Africa";s:6:"guests";s:6:"Mexico";}}
    i:1;a:6:{s:2:"id";s:32:"bfe192b9aba1e371120517daac5bf0eb";s:16:"timestamp_starts";i:1276281000;s:6:"status";s:8:"finished";s:5:"score";s:5:"0 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:7:"Uruguay";s:6:"guests";s:6:"France";}}
    i:2;a:6:{s:2:"id";s:32:"82c7f19b671b4fc2229da74767bdb6ca";s:16:"timestamp_starts";i:1276342200;s:6:"status";s:8:"finished";s:5:"score";s:5:"2 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:11:"South Korea";s:6:"guests";s:6:"Greece";}}
    i:3;a:6:{s:2:"id";s:32:"7c9fe8893bc8f3ff0a8aaee12f85f566";s:16:"timestamp_starts";i:1276351200;s:6:"status";s:8:"finished";s:5:"score";s:5:"1 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:9:"Argentina";s:6:"guests";s:7:"Nigeria";}}
    i:4;a:6:{s:2:"id";s:32:"74bba37bf12d6a4ba5d7e0c5b97bac6f";s:16:"timestamp_starts";i:1276367400;s:6:"status";s:8:"finished";s:5:"score";s:5:"1 - 1";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:7:"England";s:6:"guests";s:3:"USA";}}
    i:5;a:6:{s:2:"id";s:32:"d44babd66f4b01d4ca34f6df32fd23ea";s:16:"timestamp_starts";i:1276428600;s:6:"status";s:8:"finished";s:5:"score";s:5:"0 - 1";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:7:"Algeria";s:6:"guests";s:8:"Slovenia";}}
    i:6;a:6:{s:2:"id";s:32:"e239b69a65f21e048d2cafa1a076c888";s:16:"timestamp_starts";i:1276437600;s:6:"status";s:8:"finished";s:5:"score";s:5:"0 - 1";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:6:"Serbia";s:6:"guests";s:5:"Ghana";}}
    i:7;a:6:{s:2:"id";s:32:"d29394903e5439be30d12d86368931af";s:16:"timestamp_starts";i:1276453800;s:6:"status";s:8:"finished";s:5:"score";s:5:"4 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:7:"Germany";s:6:"guests";s:9:"Australia";}}
    i:8;a:6:{s:2:"id";s:32:"9cc41514bd8898eb7e5f95e07914cbdc";s:16:"timestamp_starts";i:1276515000;s:6:"status";s:8:"finished";s:5:"score";s:5:"2 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:11:"Netherlands";s:6:"guests";s:7:"Denmark";}}
    i:9;a:6:{s:2:"id";s:32:"fcad55449a2d2bf4a67525b78140f979";s:16:"timestamp_starts";i:1276524000;s:6:"status";s:8:"finished";s:5:"score";s:5:"1 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:5:"Japan";s:6:"guests";s:8:"Cameroon";}}
    i:10;a:6:{s:2:"id";s:32:"a8f793aee4a68de19f336652b8590752";s:16:"timestamp_starts";i:1276540200;s:6:"status";s:8:"finished";s:5:"score";s:5:"1 - 1";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:5:"Italy";s:6:"guests";s:8:"Paraguay";}}
    i:11;a:6:{s:2:"id";s:32:"d7f6201e025be54521faf91962642d9e";s:16:"timestamp_starts";i:1276601400;s:6:"status";s:11:"not_started";s:5:"score";s:5:"0 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:11:"New Zealand";s:6:"guests";s:8:"Slovakia";}}
    i:12;a:6:{s:2:"id";s:32:"3b7672b72c809fcb585c57ef4d7731f3";s:16:"timestamp_starts";i:1276610400;s:6:"status";s:11:"not_started";s:5:"score";s:5:"0 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:14:"Côte d'Ivoire";s:6:"guests";s:8:"Portugal";}}
    i:13;a:6:{s:2:"id";s:32:"e1dd97e3313dbd596709cb8fe81b3ecf";s:16:"timestamp_starts";i:1276626600;s:6:"status";s:11:"not_started";s:5:"score";s:5:"0 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:6:"Brazil";s:6:"guests";s:11:"North Korea";}}
    i:14;a:6:{s:2:"id";s:32:"8121aa6ba69e1a8b38792e5960a46bc4";s:16:"timestamp_starts";i:1276687800;s:6:"status";s:11:"not_started";s:5:"score";s:5:"0 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:8:"Honduras";s:6:"guests";s:5:"Chile";}}
    i:15;a:6:{s:2:"id";s:32:"767519ff3e1880f09c1d854192076da8";s:16:"timestamp_starts";i:1276696800;s:6:"status";s:11:"not_started";s:5:"score";s:5:"0 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:5:"Spain";s:6:"guests";s:11:"Switzerland";}}
    i:16;a:6:{s:2:"id";s:32:"d49378ba321464b7b2cac7e171e7660e";s:16:"timestamp_starts";i:1276713000;s:6:"status";s:11:"not_started";s:5:"score";s:5:"0 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:12:"South Africa";s:6:"guests";s:7:"Uruguay";}}
    i:17;a:6:{s:2:"id";s:32:"2f68be5b3c5367006ab44dfbd64e1ebf";s:16:"timestamp_starts";i:1276774200;s:6:"status";s:11:"not_started";s:5:"score";s:5:"0 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:9:"Argentina";s:6:"guests";s:11:"South Korea";}}
    i:18;a:6:{s:2:"id";s:32:"e711a8e09863ec735501a45fdc046099";s:16:"timestamp_starts";i:1276783200;s:6:"status";s:11:"not_started";s:5:"score";s:5:"0 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:6:"Greece";s:6:"guests";s:7:"Nigeria";}}
    i:19;a:6:{s:2:"id";s:32:"01c525992d2e6eb816f24a654628be4f";s:16:"timestamp_starts";i:1276799400;s:6:"status";s:11:"not_started";s:5:"score";s:5:"0 - 0";s:7:"contest";a:2:{s:5:"value";s:7:"wc_2010";s:4:"text";s:14:"World Cup 2010";}s:5:"teams";a:2:{s:5:"hosts";s:6:"France";s:6:"guests";s:6:"Mexico";}}}}
    Wie kann ich den Feed in einer Datenbank speichern (Der Feed wird von einer externen URL geladen)? Sprich Match-ID in eine Zelle, Heimteam, Gastteam, Tore Heimteam, Tore Gastteam etc...


    Und allgemein vielleicht: Bietet sich das php serialized Format überhaupt an, oder geht es mit xml oder json leichter?

    Über Eure Hilfe würde ich mich sehr freuen!

  • #2
    Was genau möchtest du machen? Entweder kannst du das ganze ja wieder unserialisieren und dann entsprechend die einzelnen Felder in einzelne Datenbankspalten speichern, eigentlich ganz einfach. Und ob das jetzt aus nem serialisiertem Array oder aus XML/JSON Strings kommt ist auch völlig egal.

    Stell mal deine Frage noch etwas konkreter.

    Kommentar


    • #3
      Zitat von high_five Beitrag anzeigen
      Wie kann ich den Feed in einer Datenbank speichern (Der Feed wird von einer externen URL geladen)?
      De-Serialisieren, dann hast du einzelne Zeilen mit den entsprechenden Einträgen. Die brauchst du dann nur noch in ein INSERT-Statement einsetzen. (Selbstverständlich Problematik SQL Injection beachten.)
      [SIZE="1"]RGB is totally confusing - I mean, at least #C0FFEE should be brown, right?[/SIZE]

      Kommentar


      • #4
        Hallo Flor1an und ChrisB!

        Vielen Dank für Eure Antworten.
        Unserializen geht klar. Dann erhalte ich folgendes:

        Code:
        array (
          'total-count' => 56,
          'items' => 
          array (
            0 => 
            array (
              'id' => '18b4511935774dabc6ecfcf3e3561ad0',
              'timestamp_starts' => 1276264800,
              'status' => 'finished',
              'score' => '1 - 1',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'South Africa',
                'guests' => 'Mexico',
              ),
            ),
            1 => 
            array (
              'id' => 'bfe192b9aba1e371120517daac5bf0eb',
              'timestamp_starts' => 1276281000,
              'status' => 'finished',
              'score' => '0 - 0',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'Uruguay',
                'guests' => 'France',
              ),
            ),
            2 => 
            array (
              'id' => '82c7f19b671b4fc2229da74767bdb6ca',
              'timestamp_starts' => 1276342200,
              'status' => 'finished',
              'score' => '2 - 0',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'South Korea',
                'guests' => 'Greece',
              ),
            ),
            3 => 
            array (
              'id' => '7c9fe8893bc8f3ff0a8aaee12f85f566',
              'timestamp_starts' => 1276351200,
              'status' => 'finished',
              'score' => '1 - 0',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'Argentina',
                'guests' => 'Nigeria',
              ),
            ),
            4 => 
            array (
              'id' => '74bba37bf12d6a4ba5d7e0c5b97bac6f',
              'timestamp_starts' => 1276367400,
              'status' => 'finished',
              'score' => '1 - 1',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'England',
                'guests' => 'USA',
              ),
            ),
            5 => 
            array (
              'id' => 'd44babd66f4b01d4ca34f6df32fd23ea',
              'timestamp_starts' => 1276428600,
              'status' => 'finished',
              'score' => '0 - 1',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'Algeria',
                'guests' => 'Slovenia',
              ),
            ),
            6 => 
            array (
              'id' => 'e239b69a65f21e048d2cafa1a076c888',
              'timestamp_starts' => 1276437600,
              'status' => 'finished',
              'score' => '0 - 1',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'Serbia',
                'guests' => 'Ghana',
              ),
            ),
            7 => 
            array (
              'id' => 'd29394903e5439be30d12d86368931af',
              'timestamp_starts' => 1276453800,
              'status' => 'finished',
              'score' => '4 - 0',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'Germany',
                'guests' => 'Australia',
              ),
            ),
            8 => 
            array (
              'id' => '9cc41514bd8898eb7e5f95e07914cbdc',
              'timestamp_starts' => 1276515000,
              'status' => 'finished',
              'score' => '2 - 0',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'Netherlands',
                'guests' => 'Denmark',
              ),
            ),
            9 => 
            array (
              'id' => 'fcad55449a2d2bf4a67525b78140f979',
              'timestamp_starts' => 1276524000,
              'status' => 'finished',
              'score' => '1 - 0',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'Japan',
                'guests' => 'Cameroon',
              ),
            ),
            10 => 
            array (
              'id' => 'a8f793aee4a68de19f336652b8590752',
              'timestamp_starts' => 1276540200,
              'status' => 'finished',
              'score' => '1 - 1',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'Italy',
                'guests' => 'Paraguay',
              ),
            ),
            11 => 
            array (
              'id' => 'd7f6201e025be54521faf91962642d9e',
              'timestamp_starts' => 1276601400,
              'status' => 'finished',
              'score' => '1 - 1',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'New Zealand',
                'guests' => 'Slovakia',
              ),
            ),
            12 => 
            array (
              'id' => '3b7672b72c809fcb585c57ef4d7731f3',
              'timestamp_starts' => 1276610400,
              'status' => 'finished',
              'score' => '0 - 0',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'Côte d\'Ivoire',
                'guests' => 'Portugal',
              ),
            ),
            13 => 
            array (
              'id' => 'e1dd97e3313dbd596709cb8fe81b3ecf',
              'timestamp_starts' => 1276626600,
              'status' => 'finished',
              'score' => '2 - 1',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'Brazil',
                'guests' => 'North Korea',
              ),
            ),
            14 => 
            array (
              'id' => '8121aa6ba69e1a8b38792e5960a46bc4',
              'timestamp_starts' => 1276687800,
              'status' => 'not_started',
              'score' => '0 - 0',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'Honduras',
                'guests' => 'Chile',
              ),
            ),
            15 => 
            array (
              'id' => '767519ff3e1880f09c1d854192076da8',
              'timestamp_starts' => 1276696800,
              'status' => 'not_started',
              'score' => '0 - 0',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'Spain',
                'guests' => 'Switzerland',
              ),
            ),
            16 => 
            array (
              'id' => 'd49378ba321464b7b2cac7e171e7660e',
              'timestamp_starts' => 1276713000,
              'status' => 'not_started',
              'score' => '0 - 0',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'South Africa',
                'guests' => 'Uruguay',
              ),
            ),
            17 => 
            array (
              'id' => '2f68be5b3c5367006ab44dfbd64e1ebf',
              'timestamp_starts' => 1276774200,
              'status' => 'not_started',
              'score' => '0 - 0',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'Argentina',
                'guests' => 'South Korea',
              ),
            ),
            18 => 
            array (
              'id' => 'e711a8e09863ec735501a45fdc046099',
              'timestamp_starts' => 1276783200,
              'status' => 'not_started',
              'score' => '0 - 0',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'Greece',
                'guests' => 'Nigeria',
              ),
            ),
            19 => 
            array (
              'id' => '01c525992d2e6eb816f24a654628be4f',
              'timestamp_starts' => 1276799400,
              'status' => 'not_started',
              'score' => '0 - 0',
              'contest' => 
              array (
                'value' => 'wc_2010',
                'text' => 'World Cup 2010',
              ),
              'teams' => 
              array (
                'hosts' => 'France',
                'guests' => 'Mexico',
              ),
            ),
          ),
        )
        Könnt ihr mir einen kurzen Beispiel Code geben, mit dem ich nun die einzelnen Felder in eine Tabelle eintragen kann?

        Sorry, stehe da ein wenig auf dem Schlauch.

        Danke!

        Kommentar


        • #5
          foreach( ...
          mysql_query( 'INSERT...

          Oder was willst du wissen? Wenn du nicht mit Arrays und Datenbanken umgehen kannst, solltest du dir mal die Tutorials im Sticky im Anfängerforum ansehen.
          [I]You know, my wife sometimes looks at me strangely. „Duncan“, she says, „there's more to life than Solaris“. Frankly, it's like she speaks another language. I mean, the words make sense individually, but put them together and it's complete nonsense.[/I]

          Kommentar


          • #6
            Könnt ihr mir einen kurzen Beispiel Code geben, mit dem ich nun die einzelnen Felder in eine Tabelle eintragen kann?
            SO läuft das hier nicht.
            [COLOR="#F5F5FF"]--[/COLOR]
            [COLOR="Gray"][SIZE="6"][FONT="Georgia"][B]^^ O.O[/B][/FONT] [/SIZE]
            „Emoticons machen einen Beitrag etwas freundlicher. Deine wirken zwar fachlich richtig sein, aber meist ziemlich uninteressant.
            [URL="http://www.php.de/javascript-ajax-und-mehr/107400-draggable-sorttable-setattribute.html#post788799"][B]Wenn man nur Text sieht, haben viele junge Entwickler keine interesse, diese stumpfen Texte zu lesen.“[/B][/URL][/COLOR]
            [COLOR="#F5F5FF"]
            --[/COLOR]

            Kommentar

            Lädt...
            X