some framework stuff
[gwvp.git] / gwvplib / gwvpdatabase.php
1 <?php
2
3 global $DB_CONNECTION;
4 $DB_CONNECTION = false;
5
6 // i need to figure out how i do data encapsulation here. We'll support mysql and sqlite3 off the bat if we can - sqlite3 comes first tho
7 function gwvp_dbCreateMysqlStructure()
8 {
9         
10 }
11
12 function gwvp_dbCreateSQLiteStructure()
13 {
14         
15 }
16
17 function gwvp_isDBSetup()
18 {
19         // for sqlite, we just check if the db exists, for everyone else, we check for a conneciton and go yay or nay
20         global $WEB_ROOT_FS, $BASE_URL, $repo_base, $data_directory, $db_type, $db_url;
21         
22         if($db_type == "sqlite") {
23                 if(file_exists($db_url)) return true;
24                 else return false;
25         }
26         
27         // TODO now for the connectables
28         // gwvp_ConnectDB();
29 }
30
31 function gwvp_ConnectDB()
32 {
33         global $WEB_ROOT_FS, $BASE_URL, $repo_base, $data_directory, $db_type, $db_url;
34         
35         // first check if $DB_CONNECTION IS live
36         if($DB_CONNECTION != false) return $DB_CONNECTION;
37         
38         // and here we go with pdo.
39         try {
40                 $DB_CONNECTION = new PDO("$db_type:$db_url");
41         } catch(PDOException $exep) {
42                 error_log("execpt on db open");
43                 return false;
44         }
45 }
46
47
48 ?>