gpt4 book ai didi

php - mysql 查询未按预期工作(编码?)

转载 作者:行者123 更新时间:2023-11-29 22:24:44 24 4
gpt4 key购买 nike

我正在我的 joomla 网站上运行 Virutmart - 这是我的代码:

$session_id = "aaa";
$quantity = 5;
$newid = 123;
$deli = "\0\0\0";
$data = '"Joomla\Registry\Registry":1:{s:7:"'.$deli.'data";O:8:"stdClass":0:{}}s:4:"user";O:5:"JUser":25:{s:9:"'.$deli.'isRoot";b:0;s:2:"id";i:0;s:4:"name";N;s:8:"username";N;s:5:"email";N;s:8:"password";N;s:14:"password_clear";s:0:"";s:5:"block";N;s:9:"sendEmail";i:0;s:12:"registerDate";N;s:13:"lastvisitDate";N;s:10:"activation";N;s:6:"params";N;s:6:"groups";a:1:{i:0;s:1:"9";}s:5:"guest";i:1;s:13:"lastResetTime";N;s:10:"resetCount";N;s:12:"requireReset";N;s:10:"'.$deli.'_params";O:24:"Joomla\Registry\Registry":1:{s:7:"'.$deli.'data";O:8:"stdClass":0:{}}s:14:"'.$deli.'_authGroups";a:2:{i:0;i:1;i:1;i:9;}s:14:"'.$deli.'_authLevels";a:3:{i:0;i:1;i:1;i:1;i:2;i:5;}s:15:"'.$deli.'_authActions";N;s:12:"'.$deli.'_errorMsg";N;s:10:"'.$deli.'_errors";a:0:{}s:3:"aid";i:0;}}__vm|a:2:{s:6:"manage";i:0;s:6:"vmcart";s:632:"{"cartProductsData":[{"virtuemart_product_id":'.$newid.',"quantity":'.$quantity.',"customProductData":[]}],"vendorId":1,"lastVisitedCategoryId":0,"virtuemart_shipmentmethod_id":"3","virtuemart_paymentmethod_id":0,"automaticSelectedShipment":true,"automaticSelectedPayment":false,"order_number":null,"BT":0,"ST":0,"cartfields":null,"couponCode":"","_triesValidateCoupon":[],"order_language":"de-DE","pricesCurrency":47,"paymentCurrency":null,"_guest":1,"_inCheckOut":false,"_inConfirm":false,"_dataValidated":false,"_confirmDone":false,"STsameAsBT":1,"selected_shipto":0,"_fromCart":false,"layout":"default","layoutPath":"","virtuemart_cart_id":0}";}';
$sq = "update c09ar_session set data='".$data."' WHERE session_id='".$session_id."'";

$db = new mysqli($host,$username,$pass,$dbname);
$db->set_charset("utf8");
$db->query($sq);

问题是分隔符变量$deli,它的数据不会按预期存储。

运行查询并检查 phpmyadmin 后,字符串片段\0\0\0 将被替换为一个奇怪的字符(见图)enter image description here使用 phpmyadmin 粘贴字符串时,我可以按预期看到\0\0\0 。

你知道我的语法有什么问题吗?我已经尝试将分隔符更改为:

$deli = "\\0\\0\\0";

没有帮助..提前致谢

最佳答案

在执行您的语句之前使用此语句。它将编码设置为utf-8

mysqli_query($mysqli_connector, "SET NAMES UTF8");

关于php - mysql 查询未按预期工作(编码?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30372975/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com