我还没有找到使用mysql
在json_set
更新我的表格的良好语法。
public function mkjson()
{
$friends = '"pachou", "eric", "francis"';
$tagfriendsjson = json_encode($friends);
try
{
include('connect.ini');
}
catch (Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$ver = 'SELECT * FROM tagusers WHERE tag_users_id="'.$_SESSION['tagusersid'].'"';
$ask = $bdd->query($ver);
$ans = $ask->fetch();
if (empty($ans['tag_friends']))
{
$req = $bdd->prepare('UPDATE tagusers SET = {"1": "pachou", "2": "eric", "3": "francis", "4": "Henry"} WHERE tag_users_id="'.$_SESSION['tagusersid'].'" ');
$req->execute();
}
else
{
}
return true;
}
:未捕获的PDOException:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;查看与您的MySQL服务器版本相对应的手册,以便在' = {" 4":" Henry"} WHERE tag_users_id =" 2&#附近使用正确的语法34;'在/var/www/tagmeyou.com/php/class.Friendlist.php:34第1行堆栈跟踪:#0 /var/www/tagmeyou.com/php/class.Friendlist.php(34):PDOStatement-&gt ; execute()#1 /var/www/tagmeyou.com/fr/vues/body/inputtag.php(23):Friendlist-> mkjson()#2 /var/www/tagmeyou.com/fr/vues/ body / bodytagscreen.php(10):include(' / var / www / tagmey ...')#3 /var/www/tagmeyou.com/fr/vues/tagscreen.php(34) :include(' / var / www / tagmey ...')#4 {main}抛出
答案 0 :(得分:0)
此查询中有两个错误:
UPDATE tagusers SET = {"1": "pachou", "2": "eric", "3": "francis", "4": "Henry"} WHERE tag_users_id="'.$_SESSION['tagusersid'].'"
首先,没有设置列名(在SET
和=
之间)。其次,JSON应该是单引号。尝试将该行更改为
$req = $bdd->prepare('UPDATE tagusers SET colname = \'"1": "pachou", "2": "eric", "3": "francis", "4": "Henry"}\' WHERE tag_users_id="'.$_SESSION['tagusersid'].'" ');
其中colname
是您要在其中存储JSON的列。