简体   繁体   English

Codeigniter DB类是否可以使用此类在表中存储JSON对象? 如果是这样怎么办?

[英]Codeigniter DB Class is it possible to store a JSON object in a table, using this class? if so how?

I am trying to store an object in a column on one of my tables, its sort of a settings logic, but I am in the process of conforming my older styling of mysql_query() style querys into the active record methods. 我试图将一个对象存储在我的一个表的一列中,这是一种设置逻辑,但是我正在将我的mysql_query()样式查询的较旧样式符合到活动记录方法中。 Of which I am now getting a 我现在正在其中

"Duplicate Entry" for PRIMARY “ PRIMARY”的“重复输入”

as an error from the DB Class, and the only thing I can associate it with is, the fact that I am attempting to pass this object which is being escaped, and I think its breaking the insert/update query 作为来自DB类的错误,我唯一可以与之关联的是,我试图传递被转义的该对象,并且我认为它破坏了插入/更新查询。

Sure, just use json_decode() ( http://www.php.net/json_decode ) and make sure it will be conform to the table-rows. 当然,只需使用json_decode()http://www.php.net/json_decode )并确保它符合表行。 Use typecasting if needed to force certain values to be correct. 如果需要强制某些值正确,请使用类型转换。

json_encode() will store your JSON string to a native PHP Array, thus making it easy to work with it from there to format it into your DB Table's format. json_encode()会将您的JSON字符串存储到本机PHP Array,因此可以轻松地从那里使用它来将其格式化为数据库表的格式。

If you add some code to your questions, I can probably give you a more detailed answer. 如果您在问题中添加一些代码,我可能会给您更详细的答案。

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

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