【问题标题】:Why update query is not working as expected in phpmyadmin?为什么更新查询在 phpmyadmin 中没有按预期工作?
【发布时间】:2016-07-11 15:17:27
【问题描述】:

我正在尝试使用 phpMyadmin 替换 wordpress 帖子内容中的一些句子 这是我的更新查询

UPDATE `wp_posts` SET `post_content` = REPLACE (`post_content`,  'Example Routes:',  'Routes:') WHERE `post_content` LIKE '%Example Routes:%';

但它显示“0 行受影响”。

我已经运行了一个具有相同条件的选择查询,以确保有结果并且我有很多结果 这是选择查询

SELECT * FROM `wp_posts` WHERE `post_content` LIKE '%Example Routes:%';

请注意,这两个查询条件与我更新的条件相同,我的条件是“LIKE '%Example Routes:%'”,更新是“REPLACE (post_content, 'Example Routes:', 'Routes: ')"。

知道为什么更新会影响到我 0 行吗?

【问题讨论】:

    标签: php mysql wordpress phpmyadmin


    【解决方案1】:

    尝试删除REPLACE 和左括号之间的空格:

    UPDATE `wp_posts` SET `post_content` = REPLACE(`post_content`,  'Example Routes:',  'Routes:') 
    WHERE `post_content` LIKE '%Example Routes:%';
    

    默认情况下,不允许在函数名称及其括号之间包含空格:http://dev.mysql.com/doc/refman/5.7/en/functions.html

    【讨论】:

      【解决方案2】:

      经过大量搜索和解决后,我想通了,选择查询给出了结果,因为 LIKE 运算符不区分大小写,但替换是,所以我需要将“示例路线:”替换为“示例路线: ' 在替换函数中,这有点棘手。

      我最终使用了这个对我有用的查询

      UPDATE `wp_posts` SET `post_content` = REPLACE(`post_content`,'Example routes:','Routes:')
      WHERE `post_content` LIKE '%Example Routes:%';
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-08-04
        • 2021-01-03
        • 2018-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多