Home > Backend Development > PHP Tutorial > laravel 里面若数据表里面存在该user_id则更新该id下的其它字段,如果不存在则新建一条记录,数据库操作如何实现?

laravel 里面若数据表里面存在该user_id则更新该id下的其它字段,如果不存在则新建一条记录,数据库操作如何实现?

WBOY
Release: 2016-06-06 20:19:47
Original
1447 people have browsed it

laravel 里面若数据表里面存在该user_id则更新该id下的其它字段,如果不存在则新建一条记录,数据库操作如何实现?我写的每次不管user_id是否存在都是更新
$resQuery = DB::update("replace INTO dog_apple_devices (user_id,apple_token, apple_adid, created_at) VALUES ('$user_id', '$apple_token', '$apple_adid', now())");

回复内容:

laravel 里面若数据表里面存在该user_id则更新该id下的其它字段,如果不存在则新建一条记录,数据库操作如何实现?我写的每次不管user_id是否存在都是更新
$resQuery = DB::update("replace INTO dog_apple_devices (user_id,apple_token, apple_adid, created_at) VALUES ('$user_id', '$apple_token', '$apple_adid', now())");

Related labels:
php
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