· 6 years ago · May 31, 2019, 04:28 PM
1<?php
2$servername = "localhost";
3$usr = "root";
4$pwd = "root";
5$dbname = "tienda";
6try {
7 $username = "admin";
8 $password = "$2y$13\$i6B17tQ/nX6J2.yg7z/St.Z6TKOyMOXw0x6KTygtHDCnWhouexAcy";
9 $email = "admin@admin.local";
10 $respuesta_de_seguridad = "pole";
11 $conn = new PDO("mysql:host=$servername;dbname=$dbname", $usr, $pwd);
12 // set the PDO error mode to exception
13 $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
14 $stmt = $conn->prepare('INSERT INTO usuarios (username, password, email, respuesta_de_seguridad) VALUES ( :username, :password, :email, :respuesta_de_seguridad)');
15 $stmt-> bindValue(":username",$username,PDO::PARAM_STR);
16 $stmt-> bindValue(":password",$password,PDO::PARAM_STR);
17 $stmt-> bindValue(":email",$email,PDO::PARAM_STR);
18 $stmt-> bindValue(":respuesta_de_seguridad",$respuesta_de_seguridad,PDO::PARAM_BOOL);
19 $stmt->execute();
20 echo "The user admin has been created with the password admin, now you can log in.";
21 }
22catch(PDOException $e)
23 {
24 echo "You cannot use this query again." . "<br>" . "If you used already this config file, please remove it urgently from the public folder, if not check your database connection data.";
25 }
26?>
27
28
29
30
31
32
33
34
35
36
37CREATE TABLE IF NOT EXISTS usuarios (
38 id INT NOT NULL AUTO_INCREMENT,
39 username VARCHAR(255) NOT NULL,
40 password VARCHAR(255) NOT NULL,
41 email VARCHAR(255) NOT NULL,
42 respuesta_de_seguridad VARCHAR(255),
43 PRIMARY KEY id(id)
44) ENGINE=INNODB;