From b5dd90d1a836aecc1e3e9af6ab1315c1ad83f7f8 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 7 Jul 2022 11:15:53 +0200 Subject: [PATCH] Code upgraded, Db\Conecction improvements --- db/connection.php | 73 +++++++++++++++++++++++++++++++++++++++++++++++ debian/changelog | 2 +- lib/util.php | 2 +- vn-autoload.php | 8 +++--- 4 files changed, 79 insertions(+), 6 deletions(-) diff --git a/db/connection.php b/db/connection.php index 619f261..8d3d76b 100644 --- a/db/connection.php +++ b/db/connection.php @@ -434,4 +434,77 @@ class Connection { return $renderedQuery; } + + function commit() { + return $this->query('COMMIT'); + } + + function rollback() { + return $this->query('ROLLBACK'); + } + + function startTransaction() { + return $this->query('START TRANSACTION'); + } + + function lastInsertId() { + return $this->getValue('SELECT LAST_INSERT_ID()'); + } + + function call($procName, $values) { + return $this->query( + "CALL {$this->quote($procName)}({$this->renderList($values)})" + ); + } + + function insert($table, $values) { + return $this->query("INSERT INTO {$this->quote($table)} + SET {$this->renderFields($values)}"); + } + + function update($table, $values, $where) { + return $this->query("UPDATE {$this->quote($table)} + SET {$this->renderFields($values)} + WHERE {$this->renderWhere($where)}"); + } + + function renderFields($values) { + return $this->renderAssoc($values, ', '); + } + + function renderWhere($operands) { + return $this->renderAssoc($operands, ' AND '); + } + + function renderAssoc($list, $separator) { + $fields = ''; + $isFirst = true; + + foreach ($list as $field => $value) { + if ($isFirst) + $isFirst = false; + else + $fields .= $separator; + + $fields .= $this->quote($field) .' = '. $this->renderValue($value); + } + + return $fields; + } + + function renderList($list, $separator = ', ') { + $values = ''; + $isFirst = true; + + foreach ($list as $value) { + if ($isFirst) + $isFirst = false; + else + $values .= $separator; + + $values .= $this->renderValue($value); + } + + return $values; + } } diff --git a/debian/changelog b/debian/changelog index 3937931..ce6388e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -php-vn-lib (2.1.9) stable; urgency=low +php-vn-lib (2.1.11) stable; urgency=low * Initial Release. diff --git a/lib/util.php b/lib/util.php index 404fb8e..039cba0 100644 --- a/lib/util.php +++ b/lib/util.php @@ -39,7 +39,7 @@ function hyphenToCamelCase($string, $upperFirst = FALSE) { $result = preg_replace_callback('/-[a-z]/', $replaceFunc, $string); if ($upperFirst) - $result = strtoupper($result{0}) . substr($result, 1); + $result = strtoupper($result[0]) . substr($result, 1); return $result; } diff --git a/vn-autoload.php b/vn-autoload.php index 4a15830..450bf5c 100644 --- a/vn-autoload.php +++ b/vn-autoload.php @@ -5,10 +5,10 @@ $vnAutoloadReplace = function($matches) { if (strlen($match) == 1) return $match; - if ($match{0} == '\\') - return '/'. $match{1}; + if ($match[0] == '\\') + return '/'. $match[1]; - return $match{0} .'-'. $match{1}; + return $match[0] .'-'. $match[1]; }; spl_autoload_register(function($className) { @@ -27,7 +27,7 @@ spl_autoload_register(function($className) { } } - if ($classPath{0} != '/') + if ($classPath[0] != '/') $classPath = stream_resolve_include_path($classPath); if (file_exists($classPath))