diff --git a/src/Crud.php b/src/Crud.php index a5d5fcc..deb84e5 100644 --- a/src/Crud.php +++ b/src/Crud.php @@ -6,7 +6,7 @@ * Classe abastrada para fazer ligação entre o banco e aplicação * * @author Bruno Morais - * @copyright GPL © 2022, bmorais.com + * @copyright GPL © 2023, bmorais.com * @package bmorais\database * @subpackage class * @access private @@ -56,6 +56,24 @@ public function insert(string $fields, array $values = null, $debug = false) return true; } + /** + * @param object $object + * @return bool|null + */ + public function insertObject(object $object) + { + $args = []; + $params = []; + foreach ($object as $chave => $valor) { + if ($valor != NULL) { + array_push($args, $chave); + array_push($params, $valor); + } + } + $args = implode(',', $args); + return $this->insert($args, $params); + } + /** * @param array $params * @return bool @@ -110,6 +128,25 @@ public function update(string $fields, array $values = null, string $where = nul return true; } + + /** + * @param object $object + * @param string $where + * @return bool|null + */ + public function updateObject(object $object, string $where){ + $args = []; + $params = []; + foreach ($object as $chave => $valor) { + if ($valor != NULL) { + array_push($args, $chave); + array_push($params, $valor); + } + } + $args = implode(',', $args); + return $this->update($args, $params, $where); + } + /** * @param array $params * @param string $where