我正在一个网站上工作,我想在其中使用 PHP 和 MySQL。大多数情况下,我将数百个变量插入到我的 MySQL 数据库中,但我对此感到厌倦。我已经在互联网上搜索了解决方案,但没有任何成功。
我的网站使用面向对象的 PHP,我想将整个实例插入数据库。例子:
class User
{
private $userID;
private $username;
// etc
public function __construct($userID, $username)
{
$this->userID = $userID;
$this->username = $username
}
// Other functions go here
}
我想知道是否可以将整个实例 ($user = new User($x, $y)) 保存到我的 MySQL 数据库中。如果可能,我需要什么字段类型?
提前致谢。