sql >> Database teknologi >  >> RDS >> Mysql

Marker for at indsætte eller opdatere tabel

Brug mysqls REPLACE INTO eller INDSÆT... PÅ DUBLIKAT NØGLOPDATERING . For eksempel:

foreach ($sheet as $data) {
    // Get Phone ID
    $dataPhoneID = mysql_escape_string($data['handset']['phone_id']);

    if (isset($stocks[$dataPhoneID])) {
        $stockPhone = $stocks[$dataPhoneID ];
        $phoneName = mysql_escape_string($stockPhone['description']);
        $stock = mysql_escape_string($stockPhone['stock']);

        $SQLInsert = "INSERT INTO phone_affiliate (affiliate_id, affiliate_phone_id, stock) ";
        $SQLInsert .= "VALUES ('1', '$dataPhoneID', '$stock') ";
        $SQLInsert .= "ON DUPLICATE KEY UPDATE stock = '$stock'";
        mysql_query($SQLInsert);
        if (mysql_insert_id()) {
            $SQLInsert = "INSERT INTO phone (name) VALUE('$phoneName')";
            mysql_query($SQLInsert);
            $phone_id = mysql_insert_id();
            $SQLUpdate = "UPDATE phone_affiliate set phone_id = $phone_id WHERE affiliate_id = 1 AND affiliate_phone_id = $dataPhoneID_id";
        }
    }
}


  1. ORA-12154:TNS:kunne ikke løse den angivne forbindelses-id

  2. Opretter du tilpassede html-tags til CMS?

  3. Sådan opretter du relationer i MySQL

  4. Opgrader MySQL til MariaDB 10 (del 1 – Installer MariaDB 5.5)