sid/manager/database.php

72 lines
2.0 KiB
PHP
Raw Normal View History

2015-10-22 12:06:49 +00:00
<?php
class DataBase{
/* ATTRIBUTS */
private $host;
private $dbname;
private $username;
private $password;
private $pdo;
2015-10-22 12:06:49 +00:00
public function __construct($host, $dbname, $username, $password){
$this->host = $host;
$this->dbname = $dbname;
$this->username = $username;
$this->password = $password;
// password: Qt358nUdyeTxLDM8
$this->pdo = new PDO('mysql:host='.$host.';dbname='.$dbname, $username, $password);
2015-10-22 12:06:49 +00:00
}
/*********************************************/
/*** création d'un utilisateur dans la bdd ***/
/*********************************************/
public function ajouterUtilisateur($username, $prenom, $nom, $email, $password, $droits){
$currentId = $this->pdo->lastInsertId();
// on applique une normalisation
$prenom = ucwords( strtolower($prenom) ); // majuscule à chaque mot sinon minuscule
$nom = strtoupper($nom); // nom en majuscules
$email = strtolower($email); // email en minuscules
$password = sha1($password); // on hash le password
$req = $this->pdo->prepare("INSERT INTO `utilisateurs`(`id_utilisateur`, `pseudo`, `prenom`, `nom`, `email`, `password`, `droits`) VALUES(default, :pseudo, :prenom, :nom, :email, :password, :droits)");
$req->execute(array(
':pseudo' => mysql_escape_string($username),
':prenom' => mysql_escape_string($prenom ),
':nom' => mysql_escape_string($nom ),
':email' => mysql_escape_string($email ),
':password' => mysql_escape_string($password),
':droits' => mysql_escape_string($droits )
));
// echo var_dump( $this->pdo->errorInfo() ).'<br>';
$addedId = $this->pdo->lastInsertId();
if( $currentId+1 == $addedId ) // si on a bien ajouté un entrée
return 'success';
else
return 'error';
}
/****************************************/
/*** création d'un groupe dans la bdd ***/
/****************************************/
2015-10-22 12:06:49 +00:00
}
$db = new DataBase("localhost", "sid", "php", "Qt358nUdyeTxLDM8");
2015-10-22 12:06:49 +00:00
?>