我無法找到這個問題的答案。pdo,將php對象插入數據庫
我想保存到mysql數據庫的一個php對象。例如:
class user{
private $id, $email, $pw, $first, $last, $group,.....;
// getters and setters
}
class someclass{
public function someFunction(){
$pdo = new PDO(...);
$objUser = new user();
$objUser->setEmail(....);
$objUser->setFirst(....);
//bla bla bla
// and i want to save this user object to DB with something like:
$pdo->insert($objUser); //in this case db table equals to class name
//instead of building/writing query manually.
//for mysql_query i have made a class for building query for insert update delete
//but mysq_query is old and deprecated
}
}
我要求這樣做的主要原因是因爲我不想寫一些可以默認存在的東西。
謝謝。
您可以利用'serialize/unserialize'內建函數。但你做錯了 – Yang
@DavidY什麼是錯的? –