]>
src.bluestatic.org Git - isso.git/blob - db_mysql.php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # All parts of this file are ©2003-[#]year[#] Iris Studios, Inc. No # ||
7 || # part of this file may be reproduced in any way: part or whole. # ||
8 || # --------------------------------------------------------------- # ||
9 || # ©2003 - [#]year[#] Iris Studios, Inc. | http://www.iris-studios.com # ||
10 || ################################################################### ||
11 \*=====================================================================*/
13 $OBJECT = 'MySQL Database Abstraction Layer';
14 $CLASS = 'MySQL_Database_Driver';
18 * MySQL Database Abstraction Layer
20 * This framework is a function wrapper for MySQL functions so we can have
21 * better error reporting and query reporting.
23 * @author Iris Studios, Inc.
24 * @copyright Copyright ©2003 - [#]year[#], Iris Studios, Inc.
28 class MySQL_Database_Driver
31 * Global environment variables
33 * @var database The name of the MySQL database used
34 * @var errshow Report errors durring execution?
35 * @var errno Current error number
36 * @var errstr Description of the current error
37 * @var link_id Link-ID for current connexion
38 * @var query_id Current query ID
39 * @var query_str Current query string
40 * @var history A list of all query reporting information
49 var $history = array();
52 * Connect to a the specified database
54 * @param str Server name
55 * @param str User name
57 * @param bool Use p-connect?
59 * @return bool Result of connect
61 function connect($server, $user, $password, $pconnect)
63 if ($this->link_id
== 0)
67 $this->link_id
= @mysql_pconnect($server, $user, $password);
71 $this->link_id
= @mysql_connect($server, $user, $password);
74 if ($this->link_id
== false)
76 $this->error('Link-Id == false, cannot connect');
80 if (@mysql_select_db($this->database
, $this->link_id
))
86 $this->error('Cannot use the database \'' . $this->database
. '\'');
93 * Send a query to MySQL
95 * @param str Query string
97 * @return res Resource ID for query
99 function query($query_str)
101 $this->query_id
= @mysql_query($query_str, $this->link_id
);
102 $this->query_str
= $query_str;
103 $this->history
[] = $this->query_str
;
105 if (!$this->query_id
)
107 $this->error('Invalid SQL query');
110 return $this->query_id
;
114 * Escape a string depending on character set
116 * @param str String to be escaped
118 * @return str Escaped string
120 function escape_string($string)
122 return @mysql_real_escape_string($string, $this->link_id
);
126 * Fetch the query result as an array
128 * @param res Query-ID
130 * @return array A row of the query result
132 function fetch_array($query_id)
134 return @mysql_fetch_array($query_id, MYSQL_ASSOC
);
138 * Fetch the query result as an object
140 * @param res Query-ID
142 * @return obj An object with the query result
144 function fetch_object($query_id)
146 return @mysql_fetch_object($query_id);
150 * Free the current MySQL query result
152 * @param res Query-ID
154 function free_result($query_id)
156 @mysql_free_result($query_id);
158 $this->query_str
= '';
162 * Send a MySQL query and return the first row of the results
164 * @param str Query string
165 * @param str Result return function (in the database layer)
167 * @return mixed Results in variable formats
169 function query_first($query_str, $callback = 'fetch_array')
171 $resource = $this->query($query_str);
172 $return = $this->$callback($resource);
173 $this->free_result($resource);
178 * Fetch the unique ID of the record just inserted
180 * @return int MySQL insert ID
184 return @mysql_insert_id($this->link_id
);
188 * Fetch the number of rows in the result
190 * @param res Query-ID
192 * @return int Number of MySQL rows
194 function num_rows($query_id)
196 return @mysql_num_rows($query_id);
200 * Fetch the number of rows affected by the query
202 * @return int Number of affected rows
204 function affected_rows($query_id)
206 return @mysql_affected_rows($this->link_id
);
210 * MySQL error wrapper for ISSO::_message()
212 * @param str User-defined error message
214 function error($message)
222 $this->errno
= mysql_errno($this->link_id
);
223 $this->errstr
= mysql_error($this->link_id
);
226 $style['code'] = 'font-family: \'Courier New\', Courier, mono; font-size: 11px;';
228 $message_prepped = "<blockquote>\n<p>";
229 $message_prepped .= "\n\t» <strong>Query:</strong>\n<br /> <pre style=\"$style[code]\">" . $this->query_str
."</pre>\n<br />";
230 $message_prepped .= "\n\t» <strong>Error Number:</strong> <span style=\"$style[code]\">" . $this->errno
. "</span>\n<br />";
231 $message_prepped .= "\n\t» <strong>Error Message:</strong> <span style=\"$style[code]\">" . $this->errstr
. "</span>\n<br />";
232 $message_prepped .= "\n\t» <strong>Additional Notes:</strong> <span style=\"$style[code]\">" . $message . "</span>\n<br />";
233 $message_prepped .= "\n\t» <strong>File:</strong> <span style=\"$style[code]\">" . $_SERVER['PHP_SELF'] . "</span>\n";
234 $message_prepped .= "\n</p>\n</blockquote>";
236 $_isso->_message('Database Error in `<em>' . $_isso->application
. '</em>`', $message_prepped, 3);
242 /*=====================================================================*\
243 || ###################################################################
246 || ###################################################################
247 \*=====================================================================*/