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