public function testRecordCanBeInsertedInTable() { $data = ['name' => 'Jaguar', 'color' => 'dark blue', 'price' => '$450,000']; $object = DbQuerries::insertInTable("cars", $data); $this->assertEquals(1, $object); $object1 = DbQuerries::selectAllRecord("cars"); $this->assertEquals(2, count($object1)); }
/** * A method to save data to database * * Used when inserting or updating a record. * It checks if the id exists, if it does then it updates a record otherwise * it inserts. */ public function save() { try { if ($this->id) { $result = DbQuerries::updateById(static::$table, $this->id, $this->properties); } else { $result = DbQuerries::insertInTable(static::$table, $this->properties); } } catch (\Exception $e) { echo $e->getMessage(); } }