简体   繁体   English

将数组添加到mysql中的字段

[英]add array to a field in mysql

I have array : $ids=[123,234,567,8910,11324,1]; 我有数组:$ ids = [123,234,567,8910,11324,1];

how to add this to one field in mysql. 如何将其添加到mysql中的一个字段。

After adding check if this id exists if it does not then add it to the same field. 添加后,检查此ID是否存在(如果不存在),然后将其添加到同一字段中。

I am looking at something like this.How do I do that .I really appreciate any help .Thanks in Advance.: 我正在看这样的东西。我该怎么做。我真的很感谢您的帮助。谢谢提前:

  --------------------- 
  | all_blocked_users |
  ---------------------
  |  123,234,567      |
  ---------------------

Right off the bat, let me tell you that storing CSV values in a database is almost never a good idea! 立即让我告诉您,将CSV值存储在数据库中几乎不是一个好主意! It demonstrates poor database design and bad data integrity. 它展示了不良的数据库设计和不良的数据完整性。 It'll likely cause issues further down the line and make working with the data later much more difficult. 这很可能会引起问题,使以后处理数据变得更加困难。

Anyway, that having been said, if you still wish to do this, you can use implode() to conver the array into a string, that can then be inserted into your MySQL database: 不管怎么说,如果您仍然希望这样做,则可以使用implode()将数组转换为字符串,然后可以将其插入到MySQL数据库中:

$dbString = implode(',', $ids);

It would be much better to store the blocked users in another link table. 将阻止的用户存储在另一个链接表中会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM