Update of /cvsroot/lambda/lambda/classes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2323/classes
Modified Files:
lambdaMySQLi.class.php
Log Message:
Added basic MySQL functions for PHP4/MySQL
Index: lambdaMySQLi.class.php
===================================================================
RCS file: /cvsroot/lambda/lambda/classes/lambdaMySQLi.class.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** lambdaMySQLi.class.php 7 Jul 2004 10:13:16 -0000 1.5
--- lambdaMySQLi.class.php 7 Jul 2004 10:37:50 -0000 1.6
***************
*** 14,18 ****
--- 14,121 ----
**/
class lambdaMySQLi {
+ /**
+ * @var array Configuration settings
+ **/
+ var $config;
+
+ /**
+ * @var object MySQL Database link
+ **/
+ var $link;
+
+ /**
+ * @var object Local reference to error handler
+ **/
+ var $handler;
+
+ /**
+ * @var int Number of performed queries
+ **/
+ var $query_count;
+
+ /**
+ * @var array Query history
+ **/
+ var $query_history;
+
+ /**
+ * Initialise the lambdaMySQLi class
+ **/
+ function lambdaMySQLi() {
+ global $handler, $config;
+
+ // Create local reference
+ $this->handler = $handler;
+
+ // Copy configuration settings
+ $this->config = $config['mysql'];
+
+ // Set default zero-values
+ $this->link = null;
+ $this->query_count = 0;
+ $this->query_history = array();
+ }
+ /**
+ * Create a connection to the MySQL database
+ *
+ * @return bool true on successful connection, otherwise false
+ **/
+ function connect() {
+ // Build the right hostname to use a non-default socket or port
+ $host = $this->config['hostname'];
+
+ if(!empty($this->config['port'])) {
+ $host .= ":" . $this->config['port'];
+ }
+ elseif (!empty($this->config['socket'])) {
+ $host .= ":" . $this->config['socket'];
+ }
+
+ // Try to establish a connection
+ // Assume the connection is successful.
+ $mylink = @mysql_connect($host, $this->config['username'],
+ $this->config['password'], true);
+
+ // Select the proper database and check for errors
+ if(!@mysql_select_db($this->config['dbname'], $mylink)) {
+ $this->handler->error("Connection to MySQL failed", true);
+ return false;
+ } else {
+ $this->link = $mylink;
+ return true;
+ }
+ }
+
+ /**
+ * Perform a query
+ *
+ * Perform a query and return the result or false
+ *
+ * @param string valid SQL query
+ * @return object MySQL Result or boolean
+ **/
+ function query($sql) {
+ // Make sure we have a valid connection
+ if(!$this->link || !@$this->connect()) {
+ return false;
+ }
+
+ // Increase query count
+ $this->query_count++;
+
+ // Add to query history
+ $this->query_history[] = $sql;
+
+ // Perform the query and return the result
+ $result = @mysql_query($sql, $this->link);
+
+ if(!$result) {
+ $this->handler->warning("Error performing query");
+ $this->handler->debug("Error performing query: $sql", 2);
+ }
+
+ return $result;
+ }
}
\ No newline at end of file
|