-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_connection.php
More file actions
79 lines (66 loc) · 2.03 KB
/
db_connection.php
File metadata and controls
79 lines (66 loc) · 2.03 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/*
* Copyright (c) 2025 Bloxtor (http://bloxtor.com) and Joao Pinto (http://jplpinto.com)
*
* Multi-licensed: BSD 3-Clause | Apache 2.0 | GNU LGPL v3 | HLNC License (http://bloxtor.com/LICENSE_HLNC.md)
* Choose one license that best fits your needs.
*
* Original PHP DB Lib Repo: https://github.com/a19836/php-db-lib/
* Original Bloxtor Repo: https://github.com/a19836/bloxtor
*
* YOU ARE NOT AUTHORIZED TO MODIFY OR REMOVE ANY PART OF THIS NOTICE!
*/
include_once __DIR__ . "/config.php";
//TEST DRIVER CONNECTION
//Connect to DB - This is optional, because any action to the DB, will trigger the connect or connectWithoutDB methods.
//$DBDriver->connect();
//$DBDriver->connectWithoutDB();
//$DBDriver->isConnected();
//$DBDriver->ping();
//$DBDriver->createDB("test2");
//$DBDriver->selectDB("test2");
try {
if ($password)
$DBDriver->connectWithoutDB();
else
throw new Exception("Please edit config.php file and define your DB credentials first!");
}
catch (Throwable $e) {
$error = $e->getMessage() . (!empty($e->problem) ? "<br/>" . $e->problem : "");
}
if ($DBDriver->isConnected()) {
//EXECUTE SQL IN DRIVER
$sql = $DBDriver->getDBsStatement();
$result = $DBDriver->getSQL($sql);
//echo "<pre>";print_r($result);die();
}
//CLOSE DRIVER CONNECTION
//$DBDriver->close();
echo $style;
//SHOW RESULTS
echo "<h1>DB Connection</h1>
<p>Connect to a DB and execute a sql statement</p>";
echo '<h4>Choose a DB driver:
<select onChange="document.location=\'?type=\' + this.value;">';
$types = DB::getAllDriverLabelsByType();
foreach ($types as $id => $label)
echo "<option value='$id'" . ($id == $type ? " selected" : "") . ">$label</option>";
echo "</select></h4>";
echo '<div class="note">
<span>
This shows how to connect to a DB and list the available DBs.
</span>
</div>';
if (!empty($error))
echo '<div class="error">' . $error . '</div>';
else {
echo "<h5>Available DBs:</h5>";
echo '<ul>';
if (!empty($result))
foreach ($result as $row) {
$k = key($row);
echo '<li>' . $row[$k] . '</li>';
}
echo '</ul>';
}
?>