This repository has been archived by the owner on Apr 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
odbctest.php
86 lines (77 loc) · 2.47 KB
/
odbctest.php
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
80
81
82
83
84
85
86
#! /usr/bin/env php
<?php
// Check for odbc extension
if (!extension_loaded('odbc')) {
echo 'ODBC exenstion needs to be available! Try to install e.g. via ' .
'"sudo apt-get install php5-odbc"' . PHP_EOL;
exit;
}
// Check for config.ini
$confiDirPath = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR;
$dsn = VOS;
$username = dba;
$password = dba;
$customConfigPath = $confiDirPath . 'config.ini';
$defaultConfigPath = $confiDirPath . 'config.ini.dist';
$config = null;
if (file_exists($customConfigPath)) {
$config = parse_ini_file($customConfigPath);
} else if (file_exists($defaultConfigPath)) {
// If not found try config.ini.dist (default settings)
$config = parse_ini_file($defaultConfigPath);
}
if (is_array($config)) {
if (isset($config['store.virtuoso.dsn'])) {
$dsn = $config['store.virtuoso.dsn'];
}
if (isset($config['store.virtuoso.username'])) {
$username = $config['store.virtuoso.username'];
}
if (isset($config['store.virtuoso.password'])) {
$password = $config['store.virtuoso.password'];
}
}
if (null === $dsn) {
// ask
echo 'DSN: ';
$dsn = trim(fgets(STDIN));
}
if (null === $username) {
// ask
echo 'Username: ';
$username = trim(fgets(STDIN));
}
if (null === $password) {
// ask
echo 'Password: ';
$password = trim(fgets(STDIN));
}
$conn = @odbc_connect($dsn, $username, $password);
if (!$conn) {
echo 'Connection failed - Something is wrong with your configuration.' . PHP_EOL;
echo 'Used connection parameters:' . PHP_EOL;
echo ' - DSN: ' . $dsn . PHP_EOL;
echo ' - Username: ' . $username . PHP_EOL;
echo ' - Password: ' . $password . PHP_EOL . PHP_EOL;
echo 'Error message: ' . odbc_errormsg() . PHP_EOL;
exit;
}
$query = 'SELECT DISTINCT ?g WHERE {GRAPH ?g { ?s ?p ?o . }}';
$result = @odbc_exec($conn, 'CALL DB.DBA.SPARQL_EVAL(\'' . $query . '\', NULL, 0)');
if (!$result) {
echo 'Query failed - Something is wrong with your configuration.' . PHP_EOL;
echo 'Used connection parameters:' . PHP_EOL;
echo ' - DSN: ' . $dsn . PHP_EOL;
echo ' - Username: ' . $username . PHP_EOL;
echo ' - Password: ' . $password . PHP_EOL . PHP_EOL;
echo 'Error message: ' . odbc_errormsg() . PHP_EOL;
@odbc_close($conn);
exit;
}
echo 'Your connection to Virtuoso seems to work fine:' . PHP_EOL;
while (@odbc_fetch_row($result)) {
echo ' - ' . @odbc_result($result, 1) . PHP_EOL;
}
if ($conn) {
@odbc_close($conn);
}