r66: Moving all DB stuff to be handled by ISSO. Working with our one big $bugsys...
[bugdar.git] / includes / db_mysql.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 class DB_Sql
14 {
15 var $database = '';
16
17 var $errno = 0;
18 var $error = '';
19
20 var $link_id = 0;
21 var $query_id = 0;
22 var $current_query = '';
23 var $query_history = array();
24
25 var $appname = 'Databsase Abstraction Layer';
26
27 function connect($server, $user, $password, $pconnect)
28 {
29 if ($this->link_id == 0)
30 {
31 if ($pconnect)
32 {
33 $this->link_id = @mysql_pconnect($server, $user, $password);
34 }
35 else
36 {
37 $this->link_id = @mysql_connect($server, $user, $password);
38 }
39
40 if (!$this->link_id)
41 {
42 $this->throw('Link-Id == false, can not connect');
43 return false;
44 }
45
46 $candb = @mysql_select_db($this->database, $this->link_id);
47 if ($candb)
48 {
49 return true;
50 }
51 else
52 {
53 $this->throw('Cannot use the database ' . $this->database);
54 }
55 }
56 }
57
58 function query($qstring)
59 {
60 $this->query_id = mysql_query($qstring, $this->link_id);
61 $this->current_query = $qstring;
62 $this->query_history[] = $this->current_query;
63
64 if (!$this->query_id)
65 {
66 $this->throw('Invalid SQL query: ' . $this->current_query);
67 }
68
69 return $this->query_id;
70 }
71
72 function fetch_array($query_id)
73 {
74 return @mysql_fetch_array($query_id, MYSQL_ASSOC);
75 }
76
77 function free_result($query_id)
78 {
79 @mysql_free_result($query_id);
80 $this->query_id = 0;
81 }
82
83 function query_first($qstring)
84 {
85 $resource = $this->query($qstring);
86 $array = $this->fetch_array($resource);
87 $this->free_result($resource);
88 return $array;
89 }
90
91 function insert_id()
92 {
93 return mysql_insert_id($this->link_id);
94 }
95
96 function num_rows($query_id)
97 {
98 return @mysql_num_rows($query_id);
99 }
100
101 function affected_rows()
102 {
103 return @mysql_affected_rows($this->link_id);
104 }
105
106 function throw($message)
107 {
108 if ($this->link_id)
109 {
110 $this->error = mysql_error($this->link_id);
111 $this->errno = mysql_errno($this->link_id);
112 }
113
114 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r";
115 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\r<head>\r<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\r<title>";
116 echo "{$this->appname} Error</title>\r<style type=\"text/css\">\r<!--\r.title\r{\r\tfont-family: Arial, Helvetica, sans-serif;\r\tfont-size: 12px;\r\tcolor: #990000;";
117 echo "\r}\rbody\r{\r\tfont-family: Arial, Helvetica, sans-serif;\r\tfont-size: 11px;\r}\r.code\r{\r\tfont-family: \"Courier New\", Courier, mono;\r\tfont-size: 11px;\r}";
118 echo "\r-->\r</style>\r</head>\r\r<body>\r<p class=\"title\"><strong>An error occured in <em>{$this->appname}</em></strong></p>\r\r<p>\r\t<blockquote>\r\t\t&raquo;";
119 echo "<strong>Query:</strong>\r\t\t<br />\r\t\t<pre class=\"code\">{$this->current_query}</pre>\r\t\t<br />\r\t\t&raquo;<strong>Error Number:</strong> ";
120 echo "<span class=\"code\">{$this->errno}</span>\r\t\t<br />\r\t\t<br />\r\t\t&raquo;<strong>Error Message:</strong> <span class=\"code\">{$this->error}</span>\r\t\t";
121 echo "<br />\r\t\t<br />\r\t\t&raquo;<strong>File:</strong> <span class=\"code\">$_SERVER[PHP_SELF]</span>\r\t</blockquote>\r</p>\r\r</body>\r</html>";
122
123 exit;
124
125 }
126 }
127
128 /*=====================================================================*\
129 || ###################################################################
130 || # $HeadURL$
131 || # $Id$
132 || ###################################################################
133 \*=====================================================================*/
134 ?>