dsa99349 2011-09-18 12:21
浏览 356
已采纳

如何在sql查询VALUES中包含分号?

I have this php script that generate an sql query. However, it needs a semicolon inside the sql statement and because of that, the sql query doesn't work.

VALUES ('Installed Modules', 'MODULE_BOXES_INSTALLED', 'bm_shopping_cart.php;bm_categories.php', 'This is automatically updated. No need to edit.', '6', '0', now())

It is included in this function.

function insert_configuration6_table($table_name9, $type) {
    global $wpdb;

    if (!empty ($wpdb->charset))
        $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
    if (!empty ($wpdb->collate))
        $charset_collate .= " COLLATE {$wpdb->collate}";

$sql = "INSERT INTO {$table_name9} (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Installed Modules', 'MODULE_BOXES_INSTALLED', 'bm_shopping_cart.php;bm_categories.php', 'This is automatically updated. No need to edit.', '6', '0', now()),('Installed Template Block Groups', 'TEMPLATE_BLOCK_GROUPS', 'boxes', 'This is automatically updated. No need to edit.', '6', '0', now());";

    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    dbDelta($sql);
}

I have searched a lot for this however, I can't find a solution that work.

How can I make an sql query that includes a semicolon(;) in the values?

Thanks.

  • 写回答

1条回答 默认 最新

  • donqh00404 2011-09-18 12:33
    关注

    The SQL Statement/syntax seems wrong. You should only have one bracket set for Values, instead you have two separated by comma. Shouldn't it be as follows?

    $sql = "INSERT INTO {$table_name9} (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Installed Modules', 'MODULE_BOXES_INSTALLED', 'bm_shopping_cart.php;bm_categories.php', 'This is automatically updated. No need to edit.', '6', '0', now());";
    

    Never mind, that was incorrect. I also think that there shouldn't be any problem with a semicolon in a SQL query; what's the actual error that you are getting?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler