-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-config.php
More file actions
50 lines (41 loc) · 1.59 KB
/
Copy pathsetup-config.php
File metadata and controls
50 lines (41 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
if ($_POST) {
$dbnamePost = $_POST["dbname"];
$usernamePost = $_POST["username"];
$dbPasswordPost = $_POST["password"];
$dbserverPost = $_POST["dbserver"];
try {
$pdo = new PDO("mysql:host=$dbserverPost;dbname=$dbnamePost", $usernamePost, $dbPasswordPost);
echo "¡Conectado correctamente!";
$codeSetting = "<?php
\$dbName = '$dbnamePost';
\$username = '$usernamePost';
\$dbPassword = '$passwordPost';
\$dbServer = '$dbserverPost';
?>";
$settingDoc = fopen("setting.php", 'w') or
die("Se produjo un error al crear el archivo");
fwrite($settingDoc, $codeSetting) or die("No se pudo escribir en el archivo");
fclose($settingDoc);
} catch (PDOException $e) {
echo "Error al conectar a la base de datos: " . $e->getMessage();
}
}
?>
<?php if(!is_file('setting.php')) {?>
<form action="" method="post">
<label for="dbname">Nombre de la base de datos</label><br>
<input type="text" id="dbname" name="dbname"><br>
<label for="username">Nombre de usuario</label><br>
<input type="text" id="username" name="username"><br>
<label for="password">Contraseña</label><br>
<input type="password" id="password" name="password"><br>
<label for="dbserver">Servidor de la base de datos</label><br>
<input type="text" id="dbserver" name="dbserver"><br>
<br>
<button type="submit">Enviar</button>
</form>
<?php } else {?>
<p>PHP Ticket se ha conectado correctamente a la base de datos.</p>
<a href="install.php">Comenzar instalación</a>
<?php } ?>