diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index 42adbb8fae..fff3092c6c 100755 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -434,50 +434,53 @@ class Database } /** - * @param string $table_name use Database::get_main_table + * @param string $tableName use Database::get_main_table * @param array $attributes Values to updates * Example: $params['name'] = 'Julio'; $params['lastname'] = 'Montoya'; - * @param array $where_conditions where conditions i.e array('id = ?' =>'4') - * @param bool $show_query + * @param array $whereConditions where conditions i.e array('id = ?' =>'4') + * @param bool $showQuery * * @return bool|int */ public static function update( - $table_name, + $tableName, $attributes, - $where_conditions = array(), - $show_query = false + $whereConditions = array(), + $showQuery = false ) { - if (!empty($table_name) && !empty($attributes)) { - $update_sql = ''; + if (!empty($tableName) && !empty($attributes)) { + $updateSql = ''; //Cleaning attributes $count = 1; + if ($showQuery) { + var_dump($attributes); + } + foreach ($attributes as $key => $value) { - $update_sql .= "$key = :$key "; + $updateSql .= "$key = :$key "; if ($count < count($attributes)) { - $update_sql.=', '; + $updateSql.= ', '; } $count++; } - if (!empty($update_sql)) { + if (!empty($updateSql)) { //Parsing and cleaning the where conditions - $where_return = self::parse_where_conditions($where_conditions); - - $sql = "UPDATE $table_name SET $update_sql $where_return "; + $whereReturn = self::parse_where_conditions($whereConditions); + $sql = "UPDATE $tableName SET $updateSql $whereReturn "; $statement = self::getManager()->getConnection()->prepare($sql); + $result = $statement->execute($attributes); - if ($show_query) { + if ($showQuery) { var_dump($sql); var_dump($attributes); var_dump($where_conditions); } if ($result) { - return $statement->rowCount(); } } diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 94cebf99a3..e77474ffa3 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -4399,6 +4399,7 @@ class SessionManager Database::update($tbl_session, $params, array('id = ?' => $session_id), true); + foreach ($enreg as $key => $value) { if (substr($key, 0, 6) == 'extra_') { //an extra field self::update_session_extra_field_value($session_id, substr($key, 6), $value);