gpt4 book ai didi

php - 无法从数据库检索序列化数据

转载 作者:行者123 更新时间:2023-11-30 00:07:51 25 4
gpt4 key购买 nike

我能够使用序列化数据正确更新数据库,但无法正确检索它。当我尝试反序列化并从数据库中检索它时,它只是回显数组。

以下是我如何使用序列化进行更新:

$query ="Update dashboard_widget_users set dashboard_widget_users.configuration='".serialize($tmp)."' where dashboard_widget_users.dsnr_yw_user =12 and dashboard_widget_users.dsnr_dashboard_widget=1";

结果:

a:4:{i:0;s:30:""Anzahl_Fahrzeuge_ohne_Bilder"";i:1;s:22:""Fahrzeuge_ohne_Preis"";i:2;s:23:""Fahrzeuge_mit_Fehlern "";i:3;s:19:""Herausforderungen"";}

这就是我尝试unserialize()并从数据库检索它的方式,但没有正确获得任何输出:

$config= unserialize($row['configuration']);
echo $config['configuration'];

这是我的代码:

if($param['aktion'] == 'save-widget-vehicle')
{
$page['register-fahrzeuge'] = array(
1 => array( 'Fahrzeug','aktiv',$page['script'],''),
0 => array( 'Edit-Fahrzeug','enabled',$page['script'],'',''),
);

$opts = !empty($param['filterOpts']) ? $param['filterOpts'] : array();

$tmp = array();
foreach ($opts as $opt) {
$tmp[] = '"'.$opt.'"';
}
$data = array();

$query ="UPDATE dashboard_widget_users w SET w.configuration=\"".mysql_real_escape_string(serialize($tmp))."\" WHERE w.dsnr_yw_user =12 AND w.dsnr_dashboard_widget=1";
$result = mysql_query($query, $myConnection);

$html = '<table width="538" cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<div>'.CreateRegister($page['register-news']).'</div>
'.CreateMessage().'
<div class="cont-liste-verlauf register">
<table id="fahrzeuge">

<tr>
<td>

</td>
</tr>


</table>
</div>
</td>
</tr>
</table>';


$return = array(
'status' => 1,
'html' => $html
);

echo json_encode($return);
die();

$param['aktion'] = 'get-widget-vehicle';
}


if($param['aktion'] == 'get-widget-vehicle')
{
$page['register-fahrzeuge'] = array(
1 => array( 'Fahrzeug','aktiv',$page['script'],''),
0 => array( 'Edit-Fahrzeug','enabled',$page['script'],'',''),
);

$data = array();

$opts = !empty($param['filterOpts']) ? $param['filterOpts'] : array();

$tmp = array();
foreach ($opts as $opt) {
$tmp[] = '"'.$opt.'"';
}

$query ='SELECT dashboard_widget_users.configuration
FROM dashboard_widget_users
INNER JOIN yw_user ON dashboard_widget_users.dsnr_yw_user = yw_user.intern
INNER JOIN dashboard_widget ON dashboard_widget_users.dsnr_dashboard_widget = dashboard_widget.id
WHERE dashboard_widget_users.dsnr_yw_user =12 AND dashboard_widget.id =1';
$result = mysql_query($query, $myConnection);

/*while ($row = mysql_fetch_assoc($result)) {
if($row['name'] == 'Anzahl_Fahrzeuge_mit_und_ohne_Bilder')
{
$sql = 'SELECT * FROM amo_bilder_live l LEFT JOIN afzdaten a ON l.dsnr_afzdaten = a.dsnr WHERE l.dsnr_afzdaten IS NULL';
$sql_result=mysql_query($sql);
//get result...
// $row['number'] = $result
}
$data[] = $row;
}*/

$html = '<table width="538" cellspacing="0" cellpadding="0" border="0" >
<tr>
<td>
<div>'.CreateRegister($page['register-fahrzeuge']).'</div>
'.CreateMessage().'
<div class="cont-liste-verlauf register"> ';
while ($row = mysql_fetch_assoc($result)) {
$config= unserialize($row['configuration']);
//$config= $row['configuration'];
$html .= '<table id="fahrzeuge">
<a href="amo_fahrzeuge.php"> '. $config .'</a>
</table>';
}
$html .= '</div>

</td>
</tr>
</table>';

$return = array(
'status' => 1,
'html' => $html
);

echo json_encode($return);
die();

}

最佳答案

您总是根据字符串的去向来转义字符串,因此您可以在将值放入数据库之前对值使用 mysqli_real_escape_string() - 而不是在检索它时来自数据库:

 $row=mysqli_fetch_assoc($result);
$config=unserialize($row['config']);

您已使用 jsonserializer 对其进行了标记 - 但您在此处使用 PHP 序列化。

关于php - 无法从数据库检索序列化数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24364457/

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