Add return type and values for update methods.

The methods `updateRowByFieldWhere` and `updateColumnByFieldWhere` in `mysql.db.php` and `pdo.php` now have a `bool` return type and explicitly return the result of the database operations. This change improves code readability and enforces consistent function outputs, aiding in better error handling and debugging.
This commit is contained in:
stephan.kasdorf
2024-12-03 11:12:24 +01:00
parent bef8735c43
commit be9d217732
2 changed files with 6 additions and 4 deletions

View File

@@ -151,10 +151,11 @@ abstract class Db implements IDb
* @param bool $wherevalue
* @param bool $rowfield
* @param bool $rowvalue
* @return bool
*/
public function updateRowByFieldWhere( $wherefield = false, $wherevalue = false, $rowfield = false, $rowvalue = false )
public function updateRowByFieldWhere( $wherefield = false, $wherevalue = false, $rowfield = false, $rowvalue = false ): bool
{
Pdo::updateColumnByFieldWhere( self::$table['table'], $rowfield, $rowvalue, $wherefield, $wherevalue );
return Pdo::updateColumnByFieldWhere( self::$table['table'], $rowfield, $rowvalue, $wherefield, $wherevalue );
}
/**

View File

@@ -166,19 +166,20 @@ final class pdo extends Mysql implements IPdo
* @param string $parameter_name
* @param string $field_name
* @param string $where_value
* @return bool
*/
public static function updateColumnByFieldWhere( $tablename = self::PLACE_TABLE_NAME,
$column_name = IMysql::PLACE_COLUMN_NAME,
$parameter_name = IMysql::PLACE_SEARCH_TERM,
$field_name = IMysql::PLACE_FIELD_NAME,
$where_value = IMysql::PLACE_WHERE_VALUE )
$where_value = IMysql::PLACE_WHERE_VALUE ): bool
{
$statement = parent::getInstance( self::getSettingsSection() )->getConn();
$query = "UPDATE " . $tablename . " SET " . $column_name . " = :" . $column_name . " WHERE " . $field_name . " = :". $field_name;
$insert = $statement->prepare($query);
$insert->bindParam( ':'.$column_name, $parameter_name );
$insert->bindParam( ':'.$field_name, $where_value );
$insert->execute();
return $insert->execute();
}
/**