From 9a2714b4d8af3481d0a68680194b03f75566efef Mon Sep 17 00:00:00 2001 From: Bruno Morais Date: Thu, 23 Feb 2023 13:35:07 -0300 Subject: [PATCH] atualizacao --- src/Crud.php | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) 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