gpt4 book ai didi

php - 将 php 对象存储到 postgresql 数据库的最佳格式

转载 作者:行者123 更新时间:2023-11-29 13:04:29 25 4
gpt4 key购买 nike

我想知道将 PHP 对象存储到数据库的最佳格式是什么,一个对象有多个参数和方法,XML 或二进制或其他格式?

例如:

$me = new Person();
$me->code= '007';
$me->name='antoine';
$me->store(); //this object is now stored into postgresql in Binary format or XML or ... you tell me !
//after few days :
$object = $database->retrievePersonByCode('007');
echo "my name is".$object->name;

怎么做?

最佳答案

您需要先将其序列化。 PHP 有一个 serialize()您可以使用的功能。但是在使用的时候要注意这一点:

Object's private members have the class name prepended to the member name; protected members have a '*' prepended to the member name. These prepended values have null bytes on either side.

根据您希望序列化的对象的大小,您可以使用 TEXTMEDIUMTEXT 甚至 LONGTEXT

关于php - 将 php 对象存储到 postgresql 数据库的最佳格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18069982/

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