假设数据库(MySQL)中需要保存多个数据实体,例如font-size、font-weight、color 等,其中一些具有固定值,另一些是应用程序用户输入的字符串,因此它们可以容纳任何字符。 所有这些信息都需要连接并存储为单个长字符串。
这些实体之间使用的最佳分隔符是什么(假设是一个小字符串),以避免在用户输入的文本中找到该分隔符的情况?
顺便说一句:我无法为每个单独的实体创建多个列。
最佳答案
也许使用一些数据结构语言,比如 json?
<?php
// Array of strings
$strings = array('string1', 'string2', 'string3');
// Encode in json (return string)
$json = json_encode($strings);
// Add to your database
funcThatUpdateYourDatabase($json);
及之后:
<?php
// Retrieve json from database;
$json = funcThatRetrieveYourColumn($json);
// convert back in array
$strings = json_decode($json);
关于mysql - 分隔连接成字符串的数据实体的最佳分隔符是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13422855/