If you had a function in a class such as:
public function insertItemToTable($item){
$sql = query("insert to table {$item}");
$insertId = sql_inserted_id();
}
Which item would you return?
- Would you return
true/falsefor the function and set a class variable to the inserted id (e.g.$this->insertedItem = sql_insert_id()) - Return the value of the inserted id
In your example, you can do both.
It’s easy to test for it in your code:
It’s a common pattern that people use, e.g.
Ultimately, it’s a preference thing, and no one right way to do it.