-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_datasource.php
84 lines (75 loc) · 3.14 KB
/
example_datasource.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
<?
/* ------------------------------------------------------------------------------------------
Exemplary use/ implementation of PHP Class "datasource"
Purpose: Provide an exemplary use of the the class "datasource" (based on configuration)
Context: It is assumed that there is a MySQL database that contains datasource information
// --------------------------------------------------------------------------------------- */
// ------------------------------------------------------------------------------------------
// Import class "datasource" and configuration
// ------------------------------------------------------------------------------------------
require_once 'config_database_server.php';
require_once 'class_datasource.php';
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
// Read datasource information from MySQL database
// ------------------------------------------------------------------------------------------
$count = 0;
try
{
// Create new PDO instance that represents a database connection
$db_internal_handle = "db_number_one";
$pdo = new PDO($database[$db_internal_handle]['server'],
$database[$db_internal_handle]['username'],
$database[$db_internal_handle]['password']);
// Build SQL command for requesting information about datasources
$tablename = "datasource";
$sql = "
SELECT
".$tablename.".*
FROM
".$tablename."
WHERE
".$tablename.".status = '1'
AND (
".$tablename.".available_datetime < '".date_format(date_create(), 'Y-m-d')."'
OR
".$tablename.".available_datetime IS NULL
)
";
// Execute SQL command and close connection to database
$data = array();
foreach ($pdo->query($sql) as $row)
{
$data[$count] = $row;
$count++;
}
$pdo = null;
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
// Check availability of datasources and update database accordingly
// ------------------------------------------------------------------------------------------
if ($count > 0)
{
for ($i=0; $i < count($data); $i++)
{
// (a) Create a new datasource object
$ds = new datasource($data[$i]);
// (b) Check availability of URL
$status = "";
$status = $ds->checkAvailabilityOfUrl($ds->getBaseUrl());
// (c) Update availability in database
$update = $ds->updateAvailabilityInDatabase($status);
}
}
else
{
exit;
}
// ------------------------------------------------------------------------------------------
?>