This commit is contained in:
xoxel
2018-12-13 06:42:08 +01:00
parent 0393733bcd
commit 46be9eb7f4
4 changed files with 195 additions and 16 deletions

View File

@ -28,7 +28,7 @@ class Model {
* @param string $idColumn
* @param int $idValue
*/
public static function update( string $tableName, array $data, string $idColumn, int $idValue ) {
public static function update( string $tableName, array $data, string $idColumn, string $idValue ) {
$reqStr = 'UPDATE ' . $tableName . ' SET ';
$lastKey = endKey( $data );
foreach ( $data as $key => $value ) {
@ -45,6 +45,40 @@ class Model {
$req = BDD::instance()->prepare( $reqStr );
$req->execute( $data );
}
public static function delete (string $tableName, array $data){
$reqStr = 'DELETE FROM ' . $tableName . ' WHERE ';
$lastKey = endKey( $data );
foreach ( $data as $key => $value ) {
$reqStr .= $key . ' = :' . $key;
if ( $key != $lastKey ) {
$reqStr .= ' AND ';
}
}
//echo $reqStr; exit();
$req = BDD::instance()->prepare( $reqStr );
$req->execute( $data );
}
public static function update_order( string $tableName, array $data, string $newOrder) {
$reqStr = 'UPDATE ' . $tableName . ' SET id_order = :newOrder WHERE ';
$lastKey = endKey( $data );
foreach ( $data as $key => $value ) {
$reqStr .= $key . ' = :' . $key;
if ( $key != $lastKey ) {
$reqStr .= ' AND ';
}
}
$data[ 'newOrder' ] = $newOrder;
//echo $reqStr; exit();
$req = BDD::instance()->prepare( $reqStr );
$req->execute( $data );
}
}
?>