Wordpress dbDelta 函数无法执行我的查询 [英] Wordpress dbDelta function fails to execute my query

查看:29
本文介绍了Wordpress dbDelta 函数无法执行我的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试转义所有字符,但没有成功.我需要专门插入这个字符串.谁能告诉我我错过了什么?其他 4 个插入语句工作正常.完整代码如下:

I have tried escaping all of the characters and that doesn't work. I need to insert this string specifically. Can anyone tell me what I'm missing? The other 4 insert statements work fine. Below is the full code:

$user_id = mysql_insert_id();


$sql1 = "INSERT INTO `wp_usermeta` VALUES (NULL, $user_id, 'nickname', '$email');
INSERT INTO `wp_usermeta` VALUES (NULL, $user_id, 'rich_editing', 'true');
INSERT INTO `wp_usermeta` VALUES (NULL, $user_id, 'comment_shortcuts', 'false');
INSERT INTO `wp_usermeta` VALUES (NULL, $user_id, 'admin_color', 'fresh');";

$sql1 .= "INSERT INTO `wp_usermeta` VALUES (NULL, $user_id, 'wp_capabilities', 'a:1:{s:10:\"subscriber\";b:1;}');";

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

谢谢

更新

问题在于字符串中的分号.我曾尝试以正常方式 () 转义这些,但这在这里似乎不起作用.该字符串现在看起来像 a:1:{s:10:\"subscriber\"\;b:1\;}有什么想法吗?

The problem lies with the semi-colons in the string. I have tried escaping these in the normal fashion () but that doesn't seem to work here. The string now looks like a:1:{s:10:\"subscriber\"\;b:1\;} Any ideas?

推荐答案

(这个答案随着 OP 提供了更多代码而演变.这是最终的简化答案!)

wordpress dbDelta 函数会分解它在 ';' 上给出的字符串,该字符串位于您的 JSON 中.您需要做的是将您的查询分成一个数组,然后将其传递给 dbDelta.

The wordpress dbDelta function explodes the string it is given on ';', which is inside your JSON. What you need to do is separate your queries into an array, and pass that to dbDelta instead.

$sql1=array();
$sql1[]="insert into....";
$sql1[]="insert into....";

dbDelta($sql1);

这篇关于Wordpress dbDelta 函数无法执行我的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆