如何在使用my_sql时查找last_insert_id ...?

时间:2017-08-31 08:03:17

标签: php mysql

$query1 = "INSERT INTO `user_order` (user_id,product_id,cart_id,product_name,product_quantity,number_of_item,total,shipping_charge,discount,total_net_amount) VALUES 
            ('$user_id','$Productid','$Cartid','$Product_name','$Quantity','$Total_Number_of_Items','$Total','$Shipping_charge','$Discount','$Total_amount')";


$run_product = mysql_query($query1);
$last_id     = mysql_insert_id();

3 个答案:

答案 0 :(得分:2)

使用LAST_INSERT_ID()函数

SELECT LAST_INSERT_ID() from user_order;

答案 1 :(得分:1)

我找到解决方案......

添加到RandomString

post.php中

library(openxlsx)
Example_function <- function(foo){
    wb <- createWorkbook()
    addWorksheet(wb, "Sheet1")
    writeData(wb, "Sheet1", bar)
    saveWorkbook(wb, "bar.xlsx")
}

然后apiclass.php传递值

     function generateRandomString($length = 30) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}
if(){$dataObj->generateRandomString());}else{
echo ResponseClass::successResponseInArray("data", null, "0" ,"data missing","False");}}

**找出最后一个插入ID:)

答案 2 :(得分:0)

LAST_INSERT_ID()应该在mysql控制台中完成。虽然我强烈建议您不要使用当前使用的旧mysql连接器并切换到PDO。