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

标签 php postgresql

我想知道将 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/

相关文章:

PHP/MySQL - 验证用户名(附加字符除外)

php - 选中多个复选框并显示多个详细信息

ruby-on-rails - 在 Rails 4 迁移中设置自定义主键时出现问题

sql - 集合运算符的 PostgreSQL 实现

database - 通过命令行在 PostgreSQL 上创建数据库

SQL : programmatically determine if table is view

php - 如何在 CentOS 7 上从 PHP 7.x 更新到 PHP 7.4

php - 在 2 echo 之间插入一个空格

php - laravel Redirect::to() 丢失端口

c++ - QTableView自动调整行高