apt-get install php5-mysql
apt-get install mysql-server
apt-get install phpmyadmin
./creerMysqlBDDetUser.sh essaiLogin essaiLogin <motDePasse>
#-- fichier : /home/$user/createTableMembreLogin.sql USE essaiLogin; DROP TABLE IF EXISTS `login`; CREATE TABLE IF NOT EXISTS login( login_id INT NOT NULL AUTO_INCREMENT, pseudo VARCHAR(20) NOT NULL, motPasse VARCHAR(100) NOT NULL, cle VARCHAR(50) NULL, actif TINYINT(1) NULL, mail VARCHAR(50) NOT NULL, lastConnect TIMESTAMP DEFAULT 0, PRIMARY KEY (login_id), UNIQUE KEY username (pseudo) )ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `membre`; CREATE TABLE IF NOT EXISTS membre( membre_id INT NOT NULL AUTO_INCREMENT, prenom VARCHAR(50) NOT NULL, nom VARCHAR(50) NOT NULL, isAdmin tinyint(1) NOT NULL DEFAULT 0, dateInscription TIMESTAMP DEFAULT CURRENT_TIMESTAMP(), dateModif TIMESTAMP DEFAULT 0, idLogin INT NOT NULL, PRIMARY KEY (membre_id), CONSTRAINT FK_login FOREIGN KEY(`idLogin`) REFERENCES login(`login_id`) )ENGINE=InnoDB DEFAULT CHARSET=utf8;
mysql -uessaiLogin -p <createTableMembreLogin.sql
#--fichier : /home/$user/insertTableMembreLogin.sql USE essaiLogin; SET FOREIGN_KEY_CHECKS=0; TRUNCATE `login`; SET FOREIGN_KEY_CHECKS=1; DELETE FROM `login`; INSERT INTO login(pseudo, motPasse, mail) VALUES ('admin', '$2y$09$vDdO6/IMSHdk/ja2MQGHfO1KJasWHNRCUDr4ZCecaZjtl4GpM3I9m', 'admin@adm.fr'); SET FOREIGN_KEY_CHECKS=0; TRUNCATE `membre`; DELETE FROM `membre`; INSERT INTO membre(prenom, nom, isAdmin, dateInscription, idLogin) VALUES ('admin', 'Admin', 1, now(), 1);
mysql -uessaiLogin -p <insertTableMembreLogin.sql
isAdmin tinyint(1)NOT NULL DEFAULT 0,
FALSE
.TRUE
sera 1
.BOOL, BOOLEAN These types are synonyms for TINYINT(1). A value of zero is considered false. Nonzero values are considered true
// pour première insertion $pseudo = "admin"; $motPasse = "admin"; echo "<p>mot de passe pour " .$pseudo. ": </p>"; $motPasseHash = password_hash($motPasse,PASSWORD_BCRYPT,['cost' => 9]); echo "<p>".$motPasseHash."</p>"; // $bool = password_verify($motPasse, $motPasseHash); var_dump($bool); // retour : //mot de passe pour admin: //$2y$09$OLK0HP3JDYjMKSoJxC00o.MCnMWHjT/sUI.rynSHxw.p9A6tSZYM. //boolean true
Pour le champ dateModif
, si on avait choisi le type DATE
à la place de TIMESTAMP
CREATE TABLE IF NOT EXISTS membre( <...> dateInscription TIMESTAMP DEFAULT CURRENT_TIMESTAMP, dateModif DATE, <...> )ENGINE=InnoDB DEFAULT CHARSET=utf8;
On aurait pu modifier la date seulement
now()
:UPDATE `membre` SET `dateModif`=NOW() WHERE `pseudo`='admin';
CURRENT_TIMESTAMP()
:UPDATE `membre` SET `dateModif`=CURRENT_TIMESTAMP() WHERE `pseudo`='admin';
select pseudo, dateModif from membre where pseudo='admin';
+-------+------------+ | pseudo | dateModif | +-------+------------+ | admin | 2016-06-24 | +-------+------------+