Skip to content

Instantly share code, notes, and snippets.

@rcervera
Created December 13, 2021 13:23
Show Gist options
  • Save rcervera/403fbfe1b851dc26ff10b697f26b5e68 to your computer and use it in GitHub Desktop.
Save rcervera/403fbfe1b851dc26ff10b697f26b5e68 to your computer and use it in GitHub Desktop.
<?php
include_once 'Model.php';
class Superheroes extends Model{
protected $taula="heroes";
// Afegir a la BD un nou superheroi
public function add($heroname,$realname,$gender,$race) {
$sql ="insert into heroes(heroname,realname,gender,race) values
(:heroname,:realname,:gender,:race)";
$ordre = $this->bd->prepare($sql);
$ordre->bindValue(':heroname',$heroname);
$ordre->bindValue(':realname',$realname);
$ordre->bindValue(':gender',$gender);
$ordre->bindValue(':race',$race);
$res = $ordre->execute();
return $res;
}
// Actualitzar les dades d'un superheroi
public function update($codi,$heroname,$realname,$gender,$race) {
$sql ="update heroes set heroname=:heroname,realname=:realname, gender=:gender, race=:race where id=:codi";
$ordre = $this->bd->prepare($sql);
$ordre->bindValue(':codi',$codi);
$ordre->bindValue(':heroname',$heroname);
$ordre->bindValue(':realname',$realname);
$ordre->bindValue(':gender',$gender);
$ordre->bindValue(':race',$race);
$res = $ordre->execute();
return $res;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment