您好 我有一个开发服务器和生产服务器都是相同的数据库。 表产品将在两台服务器上进行编辑,但仅在不同的列上进行编辑 开发:id模型图像 生产:价格和out_of_stock
我不想为此使用php。
所以我为开发服务器创建了以下查询
SELECT CONCAT( "UPDATE `products` SET `products_id` = ", products_id, ",`products_model` = '", REPLACE( products_model, "'", "\'" ) , "',`products_image` = '", products_image, "' WHERE `products`.`products_id` = ", products_id, ";" )
FROM `products`
此查询返回生产服务器的查询
UPDATE `products` SET `products_id` = 60,`products_model` = 'CT'257',`products_image` = 'ct_black01.jpg' WHERE `products`.`products_id` = 60;
UPDATE `products` SET `products_id` = 59,`products_model` = 'CT"255',`products_image` = 'ct_black01.jpg' WHERE `products`.`products_id` = 59;
UPDATE `products` SET `products_id` = 58,`products_model` = 'CT/242',`products_image` = 'ct_black01.jpg' WHERE `products`.`products_id` = 58;
UPDATE `products` SET `products_id` = 57,`products_model` = 'CT221',`products_image` = 'ct_black01.jpg' WHERE `products`.`products_id` = 57;
问题是当product_model包含'或'或两者时,我需要转义字段 然后此查询将失败
如何在不使用php的情况下执行mysql_real_escape?
谢谢
答案 0 :(得分:1)
怎么样
REPLACE(REPLACE(products_model, "'", "\\'"), '"', '\\"')
这将使用转义的单引号和双引号替换所有单引号和双引号。