(no commit message)
[freeside.git] / fs_selfservice / fri / includes / database.php
1 <?php
2
3 /**
4  * @file
5  * Functions for the database
6  */
7
8 /*
9  * Database Class
10  */
11 class Database {
12
13   /*
14    * Constructor
15    */
16   function Database() {
17
18     // PEAR must be installed
19     require_once('DB.php');
20   }
21
22   /*
23    * Logs into database and returns database handle
24    *
25
26    * @param $engine
27    *   database engine
28    * @param $dbfile
29    *   database file
30    * @param $username
31    *   username for database
32    * @param $password
33    *   password for database
34    * @param $host
35    *   database host
36    * @param $name
37    *   database name
38    * @return $dbh
39    *   variable to hold the returned database handle
40    */
41   function logon($engine,$dbfile,$username,$password,$host,$name) {
42
43     // connect string
44     if ($dbfile) {
45       // datasource mostly to support sqlite: dbengine://dbfile?mode=xxxx 
46       $dsn = $engine . '://' . $dbfile . '?mode=0666';
47     } 
48     else {
49       // datasource in in this style: dbengine://username:password@host/database 
50       $datasource = $engine . '://' . $username . ':' . $password . '@' . $host . '/' . $name;
51     }
52
53     // options
54     $options = array(
55       'debug'       => 2,
56       'portability' => DB_PORTABILITY_LOWERCASE|DB_PORTABILITY_RTRIM|DB_PORTABILITY_DELETE_COUNT|DB_PORTABILITY_NUMROWS|DB_PORTABILITY_ERRORS|DB_PORTABILITY_NULL_TO_EMPTY,
57     );
58     
59     // attempt connection
60     $dbh = DB::connect($datasource,$options); 
61
62     // if connection failed show error
63     if(DB::isError($dbh)) {
64       $_SESSION['ari_error'] .= $dbh->getMessage() . "<br><br>"; 
65       return;
66     }
67     return $dbh;
68   } 
69
70
71
72 ?>