2013-08-12 6 views
5

प्रारंभ लेनदेन mysql में अपरिभाषित है। मैं वास्तव में एक कोड से दूसरी पंक्ति में एक पंक्ति को स्थानांतरित करने के लिए अपने कोड में एकाधिक प्रश्नों को चलाने के लिए इसका उपयोग कर रहा हूं। बहुत मदद की सराहना की जाएगी। ठीक है मेरा सवाल है, मेरा Begin_transaction() क्यों परिभाषित नहीं किया गया है?प्रारंभ लेनदेन परिभाषित नहीं किया गया

<?php 
    If(isset($trade_id)){ 
      $trade_id= $_GET['trade_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->begin_transaction(); 

     // 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, profitandloss, dateclose, close) 
     SELECT session_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit, profitandloss, dateclose, close 
     FROM `opentrades` 
     WHERE `trade_id` = " . $tradeid); 
     $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(); 
    } 
    $mysqli->close(); 

      // if we successfully delete this, we 
      if ($successfullyDeleted) { 
       $_SESSION['message'] = 'Successfully deleted'; 
      } else { 
       $_SESSION['message'] = 'Unable to delete'; 
      } 

      header('Location: js.php'); 

    ?> 
+0

आप आवश्यकता के बारे में अधिक स्पष्ट हो सकता है? – rags

+0

आप एक प्रश्न पूछना भूल गए हैं। – zerkms

उत्तर

4

$mysqli->begin_transaction(); होना चाहिए $mysqli->autocommit(FALSE);

चेक इस

http://www.php.net/manual/en/mysqli.commit.php

+0

इसने त्रुटि को दूर कर दिया लेकिन हटाना नहीं हो रहा है, समस्या क्या हो सकती है? –

+0

इसके लिए आपको हटाई गई क्वेरी –

+0

जांचने की आवश्यकता है ठीक है, यह हटाए गए प्रश्न को पढ़ने में कामयाब रहा लेकिन यह सम्मिलित क्वेरी नहीं चला रहा है। –

6

PHP Manual कहते mysqli :: begin_transactionPHP संस्करण 5.5.0 या ऊपरी (http://php.net/manual/en/mysqli.begin-transaction.php) की जरूरत है।

लेकिन आप उपयोग कर सकते हैं mysqli :: autocommit बजाय (http://php.net/manual/en/mysqli.autocommit.php) पीएचपी 5.x साथ:

//Begin transaction 
$mysqli->autocommit(FALSE); 
... 
//End transaction and auto commit 
$mysqli->autocommit(TRUE); 
-2

आप इस कोड मैं परीक्षण किया है उपयोग कर सकते हैं।

वस्तु उन्मुख शैली

$cid->multi_query('start transaction;'); 
$cid->multi_query("insert into demo values('1','Pankaj','9031251290')"); 
$cid->multi_query('commit;'); 

प्रक्रियात्मक शैली

mysqli_query($link, "start transaction;"); 
mysqli_query($link, "INSERT INTO Language VALUES ('DEU', 'Bavarian', 'F', 11.2)"); 
mysqli_query($link, "commit;"); 
+0

क्यों 'multi_query'? –

+0

वास्तव में मैं एक समय में एकाधिक क्वेरी निष्पादित करता हूं इसलिए मैं इसका उपयोग करता हूं। – pankaj

संबंधित मुद्दे