开发者

how to include a semicolon in sql query 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 {$w开发者_高级运维pdb->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.


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?


As I landed here from Google, I'll add my solution even if this is very old question.

For a simple way of using semicolons or whatever other special characters in php sql query one can encode the string.

In php encode string first

base64_encode($value)

Then in the query use for example

UPDATE ... SET value = FROM_BASE64({$value}) ...

The reverse would be to use base64_dedode and TO_BASE64()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜