PHP MYSQL UPDATE如果存在或INSERT如果没有?(PHP MYSQL UPDATE if Exist or INSERT if not?)
我不知道这是否远程正确。 我有一个类,我想要更新数据库,如果这些字段当前存在或插入,如果他们没有。 复杂的是我正在加入3个表(set_colors,school_art,baseimage)
任何帮助将是非常好的。
这是我有的:
public function set_layer_colors($value) { global $db; $result_array = mysql_query(" IF EXISTS(SELECT * FROM set_colors WHERE school_art_id = '{$value}') UPDATE set_colors (school_art_id, baseimage_id, sub_folder, layer) SELECT school_art.id, baseimage.id, baseimage.sub_folder, baseimage.layer FROM school_art JOIN baseimage ON baseimage.base_folder = school_art.series_code WHERE baseimage.image_type = 'B' ORDER BY school_art.id ELSE INSERT INTO set_colors (school_art_id, baseimage_id, sub_folder, layer) SELECT school_art.id, baseimage.id, baseimage.sub_folder, baseimage.layer FROM school_art JOIN baseimage ON baseimage.base_folder = school_art.series_code WHERE baseimage.image_type = 'B' ORDER BY school_art.id "); return $result_array;
}
提前致谢。
I have no idea if this is even remotely correct. I have a class where I would like to update the database if the fields currently exist or insert if they do not. The complication is that I am doing a joining 3 tables (set_colors, school_art, baseimage)
Any help would be really great.
Here is what I have:
public function set_layer_colors($value) { global $db; $result_array = mysql_query(" IF EXISTS(SELECT * FROM set_colors WHERE school_art_id = '{$value}') UPDATE set_colors (school_art_id, baseimage_id, sub_folder, layer) SELECT school_art.id, baseimage.id, baseimage.sub_folder, baseimage.layer FROM school_art JOIN baseimage ON baseimage.base_folder = school_art.series_code WHERE baseimage.image_type = 'B' ORDER BY school_art.id ELSE INSERT INTO set_colors (school_art_id, baseimage_id, sub_folder, layer) SELECT school_art.id, baseimage.id, baseimage.sub_folder, baseimage.layer FROM school_art JOIN baseimage ON baseimage.base_folder = school_art.series_code WHERE baseimage.image_type = 'B' ORDER BY school_art.id "); return $result_array;
}
Thanks in advance.
原文:https://stackoverflow.com/questions/6853190
最满意答案
好的,我的一位同事弄清楚了:
@Path("somePostEndPoint") @POST @Produces(value={"application/vnd.api+json",MediaType.APPLICATION_JSON}) @Consumes(value={"application/vnd.api+json",MediaType.APPLICATION_JSON}) public Response postService (String someData) { //... }
不要使用
@FormParam
,只需设置一个字符串。@FormParam
需要Content-Type: application/x-www-form-urlencoded
使用
@Consumes(value={"application/vnd.api+json",MediaType.APPLICATION_JSON})
这对我们有效。
Ok a colleague of mine figured it out:
@Path("somePostEndPoint") @POST @Produces(value={"application/vnd.api+json",MediaType.APPLICATION_JSON}) @Consumes(value={"application/vnd.api+json",MediaType.APPLICATION_JSON}) public Response postService (String someData) { //... }
Do not use
@FormParam
, just set a String.@FormParam
requires theContent-Type: application/x-www-form-urlencoded
use
@Consumes(value={"application/vnd.api+json",MediaType.APPLICATION_JSON})
this worked for us.
相关问答
更多-
问题是您同时发出了帖子请求和查询请求。 模型哈希上的notes数组将在查询时获取注释记录,这将不包括新创建的注释。 此外,notes数组在创建后不会自动更新以包含新注释。 如果您希望这样做,您正在寻找的功能可以在ember数据的过滤功能中找到http://emberjs.com/api/data/classes/DS.Store.html#method_filter return Ember.RSVP.hash({ contact: this.store.findRecord('con ...
-
好的,我的一位同事弄清楚了: @Path("somePostEndPoint") @POST @Produces(value={"application/vnd.api+json",MediaType.APPLICATION_JSON}) @Consumes(value={"application/vnd.api+json",MediaType.APPLICATION_JSON}) public Response postService (String someData) ...
-
您不需要HttpServletResponse来设置响应的头。 您可以使用javax.ws.rs.core.Response来执行此操作。 只需使你的方法返回响应而不是实体: return Response.ok(entity).header("Content-Disposition", "attachment; filename=" + fileName).build() 如果您仍然希望使用HttpServletResponse,您可以将其注册到其中一个类字段,或使用属性或方法参数: @Path("/r ...
-
如何在解组之前修剪内容: import org.apache.commons.io.IOUtils; import org.apache.commons.lang.CharEncoding; MyClass myObj = MyClass.class.cast( context.createUnmarshaller().unmarshal( IOUtils.toInputStream( IOUtils.toString( InputStream.class.cas ...
-
如何使用Apache Camel实现传递式JAX-RS代理?(How do I implement a pass-through JAX-RS proxy using Apache Camel?)[2022-08-20]
这是camel-http的一个bug,我只是为它创建了一个JIRA ,并且会为它做一个快速修复。 It's a bug of camel-http, I just created a JIRA for it and will commit a quick fix for it. -
这应该工作 var url = 'http://localhost:8080/MovieRestService/resources/movies'; var sucessCallback = function(response) {...} var data = JSON.stringify({ id: 2, name: "test", director: "tes ...
-
这是JAX-RS实现中的一个错误,内置于JBoss EAP 6.2(RestEasy 2.3.7.final)。 升级到JBoss EAP 7.0解决了这个问题。 This is a bug in JAX-RS implementation that is built-in to JBoss EAP 6.2 (RestEasy 2.3.7.final). Upgrade to JBoss EAP 7.0 has solved the problem.
-
对于Glassfish 4,默认的JSON提供者是建立在JAXB之上的MOXy。 使用JAXB,实体类型需要事先知道。 所以你得到的结果只是toString()的值,这是类型不知道时的行为。 如果你想切换到使用杰克逊作为JSON提供者,它应该工作。 杰克逊并不需要事先知道类型,因为它只是反思了所有的bean属性。 要在Glassfish中使用Jackson,您需要将依赖项添加到您的项目中,并将JackonFeature注册到应用程序中。
org.glass ... -
从路径参数中删除花括号,即更改 @PathParam("{name}") String name 至 @PathParam("name") String name @Path("foo/{bar})的大括号@Path("foo/{bar})只是标识出你有一个名为bar的路径参数,但它不是参数名称的一部分。 Remove the curly braces from your path param, i.e. change @PathParam("{name}") String name to @PathPar ...
-
看看http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e323 : @GET @Path("/images/{image}") @Produces("image/*") public Response getImage(@PathParam("image") String image) { File f = new File(image); if (!f.exists()) { ...