我有这个PHP脚本生成一个SQL查询。但是,它需要在sql语句中使用分号,因此,sql查询不起作用。
VALUES ('Installed Modules', 'MODULE_BOXES_INSTALLED', 'bm_shopping_cart.php;bm_categories.php', 'This is automatically updated. No need to edit.', '6', '0', now())
它包含在此功能中。
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);
}
我已经搜索了很多,但我找不到有效的解决方案。
如何在值中创建包含分号(;)的SQL查询?
感谢。
答案 0 :(得分:1)
SQL语句/语法似乎有误。您应该只为值设置一个括号,而是用逗号分隔两个。不应该如下吗?
$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());";
击> <击> 撞击>
没关系,这是不正确的。我还认为SQL查询中的分号不应该有任何问题;你得到的实际错误是什么?