-
Notifications
You must be signed in to change notification settings - Fork 4
/
foafStore.php
88 lines (60 loc) · 1.65 KB
/
foafStore.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
87
88
<?
function dbconnection() {
$user=$GLOBAL['dbuser'];
// print "dbhost=$GLOBALS[dbhost], dbuser=$GLOBALS[dbuser], $GLOBALS[dbpass], dbname=$GLOBALS[dbname]<br>";
if (!mysql_connect($GLOBALS['dbhost'], $GLOBALS['dbuser'], $GLOBALS['dbpass'])) {
print 'Error: Connecting to dbserver<br>';
return FALSE;
}
if (!mysql_select_db($GLOBALS['dbname'])) {
print 'Error: ' . mysql_error() . '<br>';
return FALSE;
}
return TRUE;
}
// Runs the supplied query against the database and returns the result set
function dbselectquery($sql) {
if ($sql) {
// print "$sql<br>";
if ($query=mysql_query($sql)) {
while($result[]=mysql_fetch_assoc($query));
if ($result)
array_pop($result);
return $result;
}
else
print 'Error: ' . mysql_error() . '<br>';
}
return NULL;
}
// Runs the supplied update or insert query against the database.
function dbupdatequery($sql) {
if ($sql) {
// print "$sql<br>";
if (mysql_query($sql))
return TRUE;
print 'Error: ' . mysql_error() . '<br>';
}
return FALSE;
}
function dbinsertquery($sql) {
return dbupdatequery($sql);
}
function store_rdf($nickname, $rdf)
{
dbconnection();
$sql = " select * from foaf where username like '" . $nickname. "' ";
$res = dbselectquery($sql);
$sql = " insert into foaf (id, username, rdf, rdf2) VALUES (NULL, '".$nickname."', '".$rdf."', '".$rdf."') ";
foreach ($res as $result) {
$sql = " update foaf set rdf = '".$rdf."' , rdf2 = '".$rdf."' where username like '".$nickname."' ";
}
// print "$sql";
$res = dbinsertquery($sql);
}
//Connect to database
$dbhost = 'localhost';
$dbuser = 'foaf_foaf';
$dbpass = 'foaf';
$dbname = 'foaf_foaf';
?>