• Hallo Freunde,

    ich versuche mir gerade das Leben etwas leichter zu machen und habe für eine Aufgabe ein kleines Plugin geschrieben.
    Auf meinem Server habe ich ein Verzeichnis, welches diverse html-Dateien enthält. Diese Dateien werden ausgelesen und sollen dann als neue Seite in die DB gespeichert werden.
    Dazu habe ich folgendes Script geschrieben:


    Wer kann mir helfen? Danke im Voraus.

    Liebe Grüße

    • Anzeige

    Hallo!

    Wenn du gerade an deiner Website arbeitest oder dein aktuelles Hosting überdenkst: Wir betreiben mit NetzLiving eine Hosting-Plattform, die speziell auf Performance, Sicherheit und einfache Verwaltung ausgelegt ist.

    • ✔️ Schnelle Ladezeiten (optimiert für WordPress & Co.)
    • ✔️ Deutsche Server & DSGVO-konform
    • ✔️ Persönlicher Support (kein 0815-Ticket-System)

    Mehr erfahren

  • Ein Blick in den Core hilft : ;)

    [COLOR=#0088ff]/**
    [/COLOR][COLOR=#0088ff] * Insert a row into a table.
    [/COLOR][COLOR=#0088ff] *
    [/COLOR][COLOR=#0088ff] * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 'bar' ) )
    [/COLOR][COLOR=#0088ff] * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) )
    [/COLOR][COLOR=#0088ff] *
    [/COLOR][COLOR=#0088ff] * @since 2.5.0
    [/COLOR][COLOR=#0088ff] * see wpdb::prepare()
    [/COLOR][COLOR=#0088ff] * see wpdb::$field_types
    [/COLOR][COLOR=#0088ff] * see wp_set_wpdb_vars()
    [/COLOR][COLOR=#0088ff] *
    [/COLOR][COLOR=#0088ff] * Param string $table Table name
    [/COLOR][COLOR=#0088ff] * Param array $data Data to insert (in column => value pairs).
    [/COLOR][COLOR=#0088ff] * Both $data columns and $data values should be "raw" (neither should be SQL escaped).
    [/COLOR][COLOR=#0088ff] * Sending a null value will cause the column to be set to NULL - the corresponding format is ignored in this case.
    [/COLOR][COLOR=#0088ff] * Param array|string $format Optional. An array of formats to be mapped to each of the value in $data.
    [/COLOR][COLOR=#0088ff] * If string, that format will be used for all of the values in $data.
    [/COLOR][COLOR=#0088ff] * A format is one of '%d', '%f', '%s' (integer, float, string).
    [/COLOR][COLOR=#0088ff] * If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
    [/COLOR][COLOR=#0088ff] * @return int|false The number of rows inserted, or false on error.
    [/COLOR][COLOR=#0088ff] */
    [/COLOR][COLOR=#ff9d00]public function [/COLOR][COLOR=#ffdd00]insert[/COLOR][COLOR=#e1efff]( [/COLOR][COLOR=#cccccc]$table[/COLOR][COLOR=#e1efff], [/COLOR][COLOR=#cccccc]$data[/COLOR][COLOR=#e1efff], [/COLOR][COLOR=#cccccc]$format [/COLOR][COLOR=#ff9d00]= null [/COLOR][COLOR=#e1efff]) {
    [/COLOR][COLOR=#e1efff] [/COLOR][COLOR=#ff9d00]return [/COLOR][COLOR=#ff80e1]$this[/COLOR][COLOR=#ff9d00]->[/COLOR][COLOR=#ffdd00]_insert_replace_helper[/COLOR][COLOR=#e1efff]( [/COLOR][COLOR=#cccccc]$table[/COLOR][COLOR=#e1efff], [/COLOR][COLOR=#cccccc]$data[/COLOR][COLOR=#e1efff], [/COLOR][COLOR=#cccccc]$format[/COLOR][COLOR=#e1efff], [/COLOR][COLOR=#3ad900]'INSERT' [/COLOR][COLOR=#e1efff]);
    [/COLOR][COLOR=#e1efff]}[/COLOR]Der Tabellenname muss ein String sein. $wpdb->insert ('uwQrSIxN3_posts', array('ID' => 'NULL', 'post_content' => $content, 'post_title' => $filename, 'post_name' => $filename));

  • Hallo Michael,

    Vielen Dank.
    Problem gelöst. Tausend Dank
    Den Tabellennamen in einen String gestezt und das "$format" definiert. Dann lief es wie am Schnürchen.
    Hat mir viel Arbeit ersparrt.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!