2012-03-17 16 views
8

मैं तैयार बयान का इस्तेमाल किया है एक आदेश तालिका में एक आदेश को सम्मिलित करने के लेकिन अब मैं आदेश आइटम पिछले आईडी आदेश तालिका में डाला के आधार पर तालिका में आदेश आइटम सम्मिलित करना चाहते हैं:mysql_insert_id() के बराबर क्या है; तैयार कथन का उपयोग कर?

if (isset($_POST['process'])) { 

    $order_name = $_POST['order_name']; 
    //create initial order 
    $stmt = $conn2->prepare("INSERT INTO orders (order_name) VALUES (?)"); 
    $stmt->bind_param('s', $order_name); 
    $stmt->execute(); 

    //this gets the most recent auto incremented ID from the database - this is the order_id we have just created 
    $order_id = mysql_insert_id(); 

    //loop over all of our order items and add to the database 
    foreach ($_SESSION['order'] as $item) { 

क्या बराबर है तैयार कथन का उपयोग कर mysql_insert_id(); पर?

+0

क्या आपके सवाल है ? –

+0

mysql_insert_id() क्या है; तैयार कथन शैली में? – user1227124

+1

आपका मतलब है, पीडीओ लाइब्रेरी में 'mysql_insert_id' के बराबर क्या है? [दस्तावेज़ीकरण] के साथ कुछ गड़बड़ है (http://www.php.net/manual/en/pdo.lastinsertid.php)? –

उत्तर

17

यदि आप पीडीओ का उपयोग कर रहे हैं, तो यह PDO::lastInsertId() है। तो अपने डेटाबेस संभाल $link कहा जाता है यदि:

$order_id = $link->lastInsertId(); 

आप MySQLi का उपयोग कर रहे हैं, यह mysqli::$insert_id या mysqli_insert_id() है:

$order_id = $link->insert_id; 
+0

लेकिन मैं mysqli के साथ तैयार कथन का उपयोग नहीं कर रहा हूं पीडीओ – user1227124

+0

@ user1227124: फिर यह ['mysqli :: $ insert_id'] (http://php.net/manual/en/mysqli.insert-id.php) या 'mysqli_insert_id () '। – Ryan

+0

धन्यवाद यह काम किया! – user1227124

2

आप डाला आईडी प्राप्त करने के लिए $stmt->insert_id कोशिश कर सकते हैं

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