0

あるテーブルから別のテーブルに行を挿入するクエリを取得するにはどうすればよいですか? 従来の挿入選択削除を使用します。今うまくいくのは、取引を削除することです。ただし、値は新しいテーブルで更新されていません。テーブルには一致しない列があるため、2 番目のテーブルで定数を使用しました。ここで何が問題になる可能性がありますか?

<?php 
//If(!isset($trade_id)){
        $trade_id= $_GET['id'];

//}

require_once('connect.php');
$mysqli = new mysqli($database_hostname, $database_username, $database_password, $database_name) or exit("Error connecting to database");
try {
    // First of all, let's begin a transaction
    $mysqli->autocommit(FALSE);

    // A set of queries; if one fails, an exception should be thrown
    $mysqli->query("INSERT INTO `trade_history1` (session_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit,dateclose,close, profitandloss)
    SELECT session_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit, profitandloss,'null','null'
    FROM `opentrades`
    WHERE `trade_id` = " . $trade_id);
    $mysqli->query("DELETE FROM `opentrades` WHERE `trade_id` = " . $trade_id);

    // If we arrive here, it means that no exception was thrown
    // i.e. no query has failed, and we can commit the transaction
    $mysqli->commit();
    $_SESSION['message'] = 'Successfully deleted';
} catch (Exception $e) {
    // An exception has been thrown
    // We must rollback the transaction
    $_SESSION['message'] = 'Unable to delete';
    $mysqli->rollback();

}


        // if we successfully delete this, we
$mysqli->close();

// bid price,offer price, size,type,
header('location:js.php');
?>
4

3 に答える 3

0

失敗したクエリは例外をスローしません。そのクエリをエコーし​​、phpmyadmin で実行します。こんな感じで底まで掘れます。

mysqli_error()行を削除する前に、挿入クエリが正しく実行されたかどうかを確認するために使用する必要があります。

于 2013-08-12T18:46:08.350 に答える
0
  use following code
        mysqli_execute();instead of mysqli_query();



            $mysqli->execute("INSERT INTO `trade_history1` (session_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit,dateclose,close, profitandloss)
SELECT session_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit, profitandloss,'null','null'
FROM `opentrades`
WHERE `trade_id` = " . $trade_id);
$mysqli->execute("DELETE FROM `opentrades` WHERE `trade_id` = " . $trade_id);
于 2013-08-12T18:22:20.870 に答える