保存mysql数据库阵列 [英] Save array in mysql database

查看:146
本文介绍了保存mysql数据库阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要发送的订单总额为贝宝前保存额外的信息。对于每个项目我已经在我的MySQL数据库中创建一个列,我想储存。现在我想将它保存为一个数组,我可以创建一个PHP页面后阅读。额外的字段从输入表单字段服用。

I want to save extra information before sending the total order to Paypal. For each item I have created a single column in my MySQL database where I want to store it. Now I was thinking to save it as an array which I can read later for creating a PHP page. Extra fields are taken from input form fields.

通过使用数组我可以肯定不是查询股价信息?

By using an array can I be sure not to mixup information?

推荐答案

您可以使用存储阵列 连载 / 反序列化 。凭借该解决方案,他们不能轻易从其他编程语言中使用,所以你可以考虑使用 json_en code / json_de code 代替(它给你一个广泛支持的格式)。 避免的使用 / 爆炸这个,因为你可能有错误最终还是安全缺陷。

You can store the array using serialize/unserialize. With that solution they cannot easily be used from other programming languages, so you may consider using json_encode/json_decode instead (which gives you a widely supported format). Avoid using implode/explode for this since you'll probably end up with bugs or security flaws.

请注意,这使你的表中的非规范化的,这可能是一个糟糕的主意,因为你不能很容易地查询数据。因此之前前进仔细考虑这一点。愿你需要查询的数据进行统计或以其他方式?是否有其他原因正常化的数据?

Note that this makes your table non-normalized, which may be a bad idea since you cannot easily query the data. Therefore consider this carefully before going forward. May you need to query the data for statistics or otherwise? Are there other reasons to normalize the data?

另外,不要保存原始 $ _ POST 阵列。有人可以很容易地使自己的web表单和后数据到您的网站,从而发送一个真正的大形式占用大量的空间。节省您希望这些字段,并确保其保存(所以你wonät得到无效的值)之前验证数据。

Also, don't save the raw $_POST array. Someone can easily make their own web form and post data to your site, thereby sending a really large form which takes up lots of space. Save those fields you want and make sure to validate the data before saving it (so you wonät get invalid values).

这篇关于保存mysql数据库阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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