Hirdetés

Keresés

Új hozzászólás Aktív témák

  • lanszelot

    addikt

    válasz martonx #6019 üzenetére

    Köszönöm szépen.

    Valamit nem jó; értek, mert eddig jutottam, de nem jó:
    //Create another table - Main table for shared ID -This table share ID with supplier_groups
    $sql = "CREATE TABLE IF NOT EXISTS suppliers (
    supplier_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    supplier_name TEXT NOT NULL,
    group_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    FOREIGN KEY (group_id)
    REFERENCES supplier_groups (group_id))";

    try {
    $connection->exec($sql);
    echo "Table suppliers created successfully";
    } catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
    }
    //Create another table - Secondary table with shared ID - This table got ID from suppliers table
    $sql = "CREATE TABLE IF NOT EXISTS supplier_groups (
    group_id integer PRIMARY KEY,
    group_name text NOT NULL)";

    try {
    $connection->exec($sql);
    echo "Table supplier_groups created successfully";
    } catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
    }
    // Create (Insert) Data. SQL query to insert data into the "suppliers" table
    $sql = "INSERT INTO suppliers (supplier_name) VALUES ('Obi van Kenobi')";
    $sql2 = "INSERT INTO supplier_groups (group_name) VALUES ('jedi')";

    try {
    $connection->exec($sql);
    $connection->exec($sql2);
    echo "Data inserted successfully";
    } catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
    }

Új hozzászólás Aktív témák