Release 1.16. Look in CHANGELOG.txt for changes.
[fa-stable.git] / includes / db / connect_db.inc
1 <?php
2
3 set_global_connection();
4
5 function set_global_connection()
6 {
7         global $db;
8
9     if (isset($_SESSION["wa_current_user"]) && $_SESSION["wa_current_user"]->company !='')
10         $db = $_SESSION["wa_current_user"]->get_db_connection();
11     else
12         $db = null;
13 }
14
15 $db_duplicate_error_code = 1062;
16
17 //DB wrapper functions to change only once for whole application
18
19 function db_query($sql, $err_msg=null)
20 {
21         global $db, $show_sql;
22
23         //echo "<br>$sql<br>";
24         if ($show_sql)
25         {
26                 echo "<font face=arial size=2 color=000099><b>SQL..</b></font>";
27                 echo "<pre>";
28                 echo $sql;
29                 echo "</pre>\n";
30         }
31
32
33         $result = mysql_query($sql, $db);
34
35         if ($err_msg != null)
36                 check_db_error($err_msg, $sql);
37
38         return $result;
39 }
40
41 function db_fetch_row ($result)
42 {
43
44         return mysql_fetch_row($result);
45 }
46
47 function db_fetch ($result)
48 {
49
50         return mysql_fetch_array($result);
51 }
52
53 function db_seek (&$result,$record)
54 {
55         mysql_data_seek($result, $record);
56 }
57
58 function db_free_result ($result)
59 {
60         if ($result)
61                 mysql_free_result($result);
62 }
63
64 function db_num_rows (&$result)
65 {
66         return mysql_num_rows($result);
67 }
68
69 function db_num_fields ($result)
70 {
71         return mysql_num_fields($result);
72 }
73
74 function db_escape ($result)
75 {
76         return mysql_escape_string($result);
77 }
78
79 function db_error_no ()
80 {
81         global $db;
82         return mysql_errno($db);
83 }
84
85 function db_error_msg($conn)
86 {
87         return mysql_error($conn);
88 }
89
90 function db_insert_id()
91 {
92         global $db;
93         return mysql_insert_id($db);
94 }
95
96 function db_num_affected_rows()
97 {
98         global $db;
99         return mysql_affected_rows($db);
100 }
101
102 ?>