0

我记录访问者的IP地址并将其存储到mysql数据库中。如果访问者获得了不同的 ip,它也会更新记录。我使用以下代码进行更新,以下示例中的值仅用于测试。

insert into visiter_info values ('1344594088179','0','100.100.100.100','china','300x600','IOS','firefox','')
                    ON DUPLICATE KEY UPDATE 
                    ip_address=concat(ip_address,'|','100.100.100.100'),
                    location=concat(location,'|','china'),
                    screen_res=concat(screen_res,'|','300x600'),
                    os=concat(os,'|','IOS'),
                    brower=concat(brower,'|','firefox')

它可以工作,但是现在问题来了,我如何检查数据库中是否有记录?像这样:访客又来了,ip 100.100.100.100。mysql不知道有记录,会重新记录。如何在插入之前检查是否包含子字符串?

4

1 回答 1

0
    if not exists(select * from visiter_info where ip_address='100.100.100.100')
    insert into visiter_info values ('1344594088179','0','100.100.100.100','china','300x600','IOS','firefox','') 
ON DUPLICATE KEY UPDATE  
        ip_address=concat(ip_address,'|','100.100.100.100'), 
        location=concat(location,'|','china'), 
        screen_res=concat(screen_res,'|','300x600'), 
        os=concat(os,'|','IOS'), 
        brower=concat(brower,'|','firefox') 
于 2012-08-10T11:20:42.047 回答