获取自动递增 int 并插入到另一列
我正在尝试创建一个新行,其中图像名称与 recordID 相同(加上“.png”)。 recordID 是一个自动递增的 int。
这会创建一条新记录:
mysql_query("INSERT INTO record (name,age) VALUES ('$name','$age'')");
..并且这会获取 recordID:
$newRecordID = mysql_insert_id();
但是如何将 recordID 的值粘贴到 image_name 列(加上“.png”)中,而无需再次搜索它?
I'm trying to create a new row, in which the image name is the same as the recordID (plus '.png'). The recordID is an auto-incremented int.
This makes a new record:
mysql_query("INSERT INTO record (name,age) VALUES ('$name','$age'')");
..and this gets the recordID:
$newRecordID = mysql_insert_id();
but how do stick the recordID's value into a image_name column (plus '.png'), without having to search for it again?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您根本不需要将“.png”粘贴到图像上,您的逻辑意味着每个记录都包含有关扩展名为 png 的图像的信息。为什么还需要另一列来存储图像名称?
第二部分是您使用保留字作为列名。关键字
NAME
已被保留,您应该始终避免使用它。You don't need to stick '.png' to your image at all, your logic implies that each record contains info about image with extension png. Why would you even need another column then to store the image name?
The second part is that you are using a reserved word for your column name. Keyword
NAME
is reserved, you should always avoid it.据我所知,MySQL 不提供序列操作函数。所以你不能。
您能做的最好的事情就是将其包装在存储过程中,以避免与服务器的往返。
Best I'm aware MySQL offers no sequence manipulation functions. So you can't.
The best you can do is to wrap this in a stored procedure to avoid a round trip to the server.
也许我在这里缺少一些东西但是
Maybe im missing somthing here but