-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
77 lines (58 loc) · 2.52 KB
/
example.php
File metadata and controls
77 lines (58 loc) · 2.52 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
<?php
require_once '../../vendor/autoload.php';
use WebFiori\Database\ConnectionInfo;
use WebFiori\Database\Database;
const SEP = "────────────────────────────────────────────────────────────────────\n";
echo "=== WebFiori Database Connection Example ===\n\n";
try {
// Create connection info
echo SEP;
echo "1. Creating Connection Info:\n";
$connection = new ConnectionInfo('mysql', 'root', '123456', 'mysql');
echo " ✓ Connection info created\n";
echo " Database Type: ".$connection->getDatabaseType()."\n";
echo " Host: ".$connection->getHost()."\n";
echo " Database: ".$connection->getDBName()."\n\n";
// Establish database connection
echo SEP;
echo "2. Establishing Connection:\n";
$database = new Database($connection);
echo " ✓ Database connection established\n\n";
// Test connection with a simple query
echo SEP;
echo "3. Testing Connection:\n";
$result = $database->raw("SELECT VERSION() as version")->execute();
if ($result) {
echo " ✓ Connection test successful\n";
$rows = $result->getRows();
if (!empty($rows)) {
echo " MySQL Version: ".$rows[0]['version']."\n";
}
}
echo "\n";
// Additional connection tests
echo SEP;
echo "4. Additional Connection Info:\n";
$result = $database->raw("SELECT DATABASE() as current_db")->execute();
if ($result && $result->getRowsCount() > 0) {
echo " ✓ Current database: ".$result->getRows()[0]['current_db']."\n";
}
$result = $database->raw("SHOW STATUS LIKE 'Uptime'")->execute();
if ($result && $result->getRowsCount() > 0) {
$uptime = $result->getRows()[0]['Value'];
echo " ✓ Server uptime: ".$uptime." seconds\n";
}
$result = $database->raw("SELECT CONNECTION_ID() as connection_id")->execute();
if ($result && $result->getRowsCount() > 0) {
echo " ✓ Connection ID: ".$result->getRows()[0]['connection_id']."\n";
}
$result = $database->raw("SELECT USER() as user_name")->execute();
if ($result && $result->getRowsCount() > 0) {
echo " ✓ Current User: ".$result->getRows()[0]['user_name']."\n";
}
} catch (Exception $e) {
echo "✗ Error: ".$e->getMessage()."\n";
echo "Note: Make sure MySQL is running and accessible with the provided credentials.\n";
}
echo "\n".SEP;
echo "=== Example Complete ===\n";