我怎么能一次将数据插入两个表?

时间:2017-03-11 08:57:00

标签: php mysql

我需要执行两个查询,但插入将在一个表上发生(仅限第一个查询)。如果我先放置query9,它将执行,否则查询3.

$query9 = $con->prepare("INSERT INTO complete_status (ID, hotel_id, 
floor_id, room_id, pull_chrdsw_status, emergency_status, nurse_callsw_status, cmr_status, foodsw_status, bedside_cancelsw_status ,nurse_distress_status, bcssw_status ,final_status,date1, Time) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)");           
$query9->bind_param("iiiiiiiiiiiii", $ID, $HotelID ,$SectorID, $RoomID, $pull_chrdsw_status, $emergency_status, $nurse_callsw_status, $cmr_status, $foodsw_status,$bedside_cancelsw_status, $nurse_distress_status, $bcssw_status,$statuss);


if($value->NurseCallSwStats != $Uploadedpkt->RoomStatus[$key]->NurseCallSwStats)
{
    if($DebugMode===TRUE)// Test mode with debugg outputs
    {
        echo "<br>";
        echo "laundry change";
    }
    $Difference_Flag=TRUE;
    $nurse_callsw_status = $Uploadedpkt->RoomStatus[$key]->NurseCallSwStats;
    $query3->execute();
    $query9->execute(); 
}   


foreach ($Uploadedpkt->RoomStatus as $key => $value) 
{   
    $nurse_callsw_status = $Uploadedpkt->RoomStatus[$key]->NurseCallSwStats;
    $query3->execute(); 
    $query9->execute(); 
}   

1 个答案:

答案 0 :(得分:0)

您可以创建一个包含所有查询的stored procedure,然后执行它。