]>
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 (defined('ISSO_SHOW_QUERIES_LIVE'))
107 if (constant('ISSO_SHOW_QUERIES_LIVE'))
109 print($this->query_str
. '<hr />');
113 if (!$this->query_id
)
115 $this->error('Invalid SQL query');
118 return $this->query_id
;
122 * Escape a string depending on character set
124 * @param str String to be escaped
126 * @return str Escaped string
128 function escape_string($string)
130 return @mysql_real_escape_string($string, $this->link_id
);
134 * Fetch the query result as an array
136 * @param res Query-ID
138 * @return array A row of the query result
140 function fetch_array($query_id)
142 return @mysql_fetch_array($query_id, MYSQL_ASSOC
);
146 * Fetch the query result as an object
148 * @param res Query-ID
150 * @return obj An object with the query result
152 function fetch_object($query_id)
154 return @mysql_fetch_object($query_id);
158 * Free the current MySQL query result
160 * @param res Query-ID
162 function free_result($query_id)
164 @mysql_free_result($query_id);
166 $this->query_str
= '';
170 * Send a MySQL query and return the first row of the results
172 * @param str Query string
173 * @param str Result return function (in the database layer)
175 * @return mixed Results in variable formats
177 function query_first($query_str, $callback = 'fetch_array')
179 $resource = $this->query($query_str);
180 $return = $this->$callback($resource);
181 $this->free_result($resource);
186 * Fetch the unique ID of the record just inserted
188 * @return int MySQL insert ID
192 return @mysql_insert_id($this->link_id
);
196 * Fetch the number of rows in the result
198 * @param res Query-ID
200 * @return int Number of MySQL rows
202 function num_rows($query_id)
204 return @mysql_num_rows($query_id);
208 * Fetch the number of rows affected by the query
210 * @return int Number of affected rows
212 function affected_rows($query_id)
214 return @mysql_affected_rows($this->link_id
);
218 * MySQL error wrapper for ISSO::_message()
220 * @param str User-defined error message
222 function error($message)
230 $this->errno
= mysql_errno($this->link_id
);
231 $this->errstr
= mysql_error($this->link_id
);
234 $style['code'] = 'font-family: \'Courier New\', Courier, mono; font-size: 11px;';
236 $message_prepped = "<blockquote>\n<p>";
237 $message_prepped .= "\n\t» <strong>Query:</strong>\n<br /> <pre style=\"$style[code]\">" . $this->query_str
."</pre>\n<br />";
238 $message_prepped .= "\n\t» <strong>Error Number:</strong> <span style=\"$style[code]\">" . $this->errno
. "</span>\n<br />";
239 $message_prepped .= "\n\t» <strong>Error Message:</strong> <span style=\"$style[code]\">" . $this->errstr
. "</span>\n<br />";
240 $message_prepped .= "\n\t» <strong>Additional Notes:</strong> <span style=\"$style[code]\">" . $message . "</span>\n<br />";
241 $message_prepped .= "\n\t» <strong>File:</strong> <span style=\"$style[code]\">" . $_SERVER['PHP_SELF'] . "</span>\n";
242 $message_prepped .= "\n</p>\n</blockquote>";
244 $_isso->_message('Database Error in `<em>' . $_isso->application
. '</em>`', $message_prepped, 3);
250 /*=====================================================================*\
251 || ###################################################################
254 || ###################################################################
255 \*=====================================================================*/