My question is how should i be inserting php class objects into the database? If i have
Cat.php
class Cat{ private $name; public function setName($name){ $this->name = $name } public function database(){ ....$this->name; //Insert stuff into db } } Somefile.php
if($_POST['catname']){ //This way? $obj1 = new Cat(); $obj1->setName($_POST['catname']); $obj1->database(); //Or this way //Insert Cat directly into the db without creating an object of Cat } And i want to insert this cat into the database. Would it be best to create a function within cat that gets $this->name or before i create the object should i just insert it into the database?
Serializableinterface, then implementwriteObjectandreadObjectmethods on any class that is serializable.