SQL implementation has data to update, no insert

Source: Internet
Author: User

First build the table:

CREATE TABLE Lxt_user3 (
user_id int unsigned NOT NULL primary key auto_increment comment ' user ID ',
qq_open_id varch AR (+) unique,---------------The table must have a unique field, otherwise the following SQL statement will not perform as expected
role_id int unsigned not NULL,
Category _id int unsigned,
status int unsigned,
name varchar (default '),
img varchar (+) default ',
password var char (+) default ',
Salt varchar (4) Default ',
Sex int,
email varchar (+) Default ',
Telephone varchar (20 Default ',
Address varchar (+) default ',
Navigation varchar (+) Default ',
Simple_menu varchar (1000) Default ',
Dashboard text,
Reg_ip varchar (0) Default ',
reg_time int unsigned default,
Last_login_time int unsigned default 0,
lostpw_time int unsigned default 0,
Weixinid int,
Last_read_time varchar ($) Default ' ,
Qqnumber int,
Realname varchar (+) Default ',
Position varchar (default '
) Engine=myisam default Charset=utf8 comment ' user table ';

A key SQL statement:

$sql = "INSERT into Lxt_user3 SET realname= ' $realname ', role_id= ' $role _id ', sex= ' $sex ', name= ' $name ', qq_open_id= ' $qq _ open_id ' on DUPLICATE KEY UPDATE realname= ' $realname ', role_id= ' $role _id ', sex= ' $sex ', name= ' $name ', qq_open_id= ' $qq _ Open_id ' ";

SQL implementation has data to update, no insert

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.