mysql 更新最后插入的 id [英] mysql updating last inserted id

查看:49
本文介绍了mysql 更新最后插入的 id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过获取最后插入的 id 来更新表,但它没有给出任何结果.这是查询:

 $quer = mysql_query("更新日期SET d_startdate = '$start', d_enddate = '$end'WHERE d_id = LAST_INSERT_ID() AND d_sid = $id");

d_id 是主键,d_sid 是另一个表的外键

解决方案

我在同一张表上使用了 INSERT 和 UPDATE 操作,并且工作正常.您可以根据需要更改此查询.

";打印_r($res);$query = '更新项目集名称="DELTaaaA1" WHERE id = LAST_INSERT_ID()';$res = mysql_query($query, $con) 或 die(mysql_error());打印_r($res);?>

它应该返回 1 1

I want to update a table by getting the last inserted id but it is giving no results. here is the query :

 $quer = mysql_query("UPDATE date 
                      SET d_startdate = '$start', d_enddate = '$end' 
                      WHERE d_id = LAST_INSERT_ID() AND d_sid = $id");

d_id is the primary key and d_sid is a foreign key of another table

解决方案

I have used INSERT as well as UPDATE operation on my same table and its working fine. You can change this query as per your need.

<?php
$con = mysql_connect("localhost","root","") or die("Could not connect");
mysql_selectdb("test", $con);
$query = 'INSERT INTO item (`name`) VALUES ("DELTaaaA")';
$res = mysql_query($query, $con) or die(mysql_error());
echo "<pre>";
print_r($res);
$query = 'UPDATE item set name="DELTaaaA1" WHERE id = LAST_INSERT_ID()';
$res = mysql_query($query, $con) or die(mysql_error());
print_r($res);
?>

It should return 1 1

这篇关于mysql 更新最后插入的 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆