请问mysql的有关问题

WBOY
Release: 2016-06-13 10:17:29
Original
903 people have browsed it

请教mysql的问题
想只用sql而不用php代码实现如下功能:如果一条记录存在返回其id,如果不存在,插入并返回其id,可以实现吗?如何实现?望各位大侠详细指教

------解决方案--------------------
执行insert into table () values () on duplicate key update ……

那么mysql_insert_id() 返回就是自增id

不过mysql_insert_id可是php函数哦
------解决方案--------------------

SQL code
INSERT IGNORE INTO table () VALUES ();<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template