[phpMP-CVS] CVS: phpMP/core/dba mysql.php,1.13,1.14
Status: Pre-Alpha
Brought to you by:
heimidal
|
From: Adam A. <ra...@us...> - 2003-10-09 04:34:24
|
Update of /cvsroot/phpmp/phpMP/core/dba
In directory sc8-pr-cvs1:/tmp/cvs-serv842/core/dba
Modified Files:
mysql.php
Log Message:
Cleaned up file, remove row_seek (not needed), removed many unneccessary statements, standardised on passing NULL references for null variables
Index: mysql.php
===================================================================
RCS file: /cvsroot/phpmp/phpMP/core/dba/mysql.php,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** mysql.php 5 Oct 2003 22:10:32 -0000 1.13
--- mysql.php 9 Oct 2003 04:34:19 -0000 1.14
***************
*** 22,33 ****
*/
! //
! // some parts of this file based upon code in phpBB 2.0.6
! //
!
! //
! // To clear up misconception, there will be use of a error handler in the future
! // when one is written ^_^
! //
class sql_db
--- 22,26 ----
*/
! // MySQL 3.x/4.0 Database API
class sql_db
***************
*** 36,46 ****
var $db_query_result = 0;
var $db_query_count = 0;
- var $db_row = array();
var $db_rowset = array();
! //
! // CONSTRUCTOR - sql_connect
! //
! function sql_db($hostname, $port, $username, $password, $database, $persistant)
{
$this->hostname = $hostname;
--- 29,36 ----
var $db_query_result = 0;
var $db_query_count = 0;
var $db_rowset = array();
! // Open database connection, select database
! function sql_connect($hostname, $port, $username, $password, $database, $persistant = NULL, $error_handling = NULL )
{
$this->hostname = $hostname;
***************
*** 51,55 ****
$this->persistant = $persistant;
! if( $this->persistant)
{
$this->db_connection_id = @mysql_pconnect($this->hostname, $this->username, $this->password);
--- 41,45 ----
$this->persistant = $persistant;
! if( !is_null($this->persistant) )
{
$this->db_connection_id = @mysql_pconnect($this->hostname, $this->username, $this->password);
***************
*** 61,67 ****
}
! if(! $this->db_connection_id)
{
! return false;
}
else
--- 51,64 ----
}
! if( !$this->db_connection_id )
{
! if( !is_null($error_handling) )
! {
! // to db error handler (ERROR_FLAG, $this->sql_error($this->db_connection_id), $this->sql_errno($this->db_connection_id));
! }
! else
! {
! return false;
! }
}
else
***************
*** 69,130 ****
if(! empty($this->database))
{
! $dbselect = @mysql_select_db($this->database);
! if(! $dbselect)
{
! @mysql_close($this->db_connection_id);
! $this->db_connection_id = $dbselect;
}
}
return $this->db_connection_id;
}
}
! //
! // DESTRUCTOR - sql_close
! // - based on sql_close from phpBB 2.0.6
! //
! function sql_close($db_connect_id = 0)
{
! if($db_connect_id == 0)
{
$db_connect_id = $this->db_connection_id;
}
! if($db_connect_id != FALSE)
! {
! if($this->db_query_result)
! {
! @mysql_free_result($this->db_query_result);
! }
! $result = @mysql_close($db_connect_id);
! return $result;
! }
! else
! {
! return false;
! }
! }
!
! //
! // OTHER BASE METHODS
! //
!
! //
! // sql_query
! //
! function sql_query($query = '', $return_off = TRUE)
{
! unset($this->db_query_result); // remove previous query result
! if(! empty($query))
{
$this->db_query_count++;
! $this->db_query_result = @mysql_query($query, $this->db_connection_id);
}
if( $this->db_query_result)
{
- unset($this->db_row[$this->db_query_result]);
unset($this->db_rowset[$this->db_query_result]);
return $this->db_query_result;
--- 66,115 ----
if(! empty($this->database))
{
! if( !is_null($error_handling) )
{
! // to db error handler (ERROR_FLAG, $this->sql_error($this->db_connection_id), $this->sql_errno($this->db_connection_id));
! }
! else
! {
! return false;
}
}
+
return $this->db_connection_id;
}
}
! function sql_close($db_connect_id = NULL)
{
! if( is_null($db_connect_id) )
{
$db_connect_id = $this->db_connection_id;
}
! if($db_connect_id != FALSE)
! {
! if($this->db_query_result)
! {
! @mysql_free_result($this->db_query_result);
! }
!
! return @mysql_close($db_connect_id);
! }
! }
!
! // Query database
! function sql_query($sql, $sql_explain = NULL, $line = NULL, $file = NULL )
{
! $this->sql_free_result($this->db_query_result); // remove previous query result
! if(! empty($sql))
{
$this->db_query_count++;
! $this->db_query_result = @mysql_query($sql, $this->db_connection_id);
}
if( $this->db_query_result)
{
unset($this->db_rowset[$this->db_query_result]);
return $this->db_query_result;
***************
*** 132,138 ****
else
{
! if($return_off == TRUE)
{
! die(mysql_error());
}
else
--- 117,123 ----
else
{
! if( !is_null($sql_explain) )
{
! // to db error handler (ERROR_FLAG, $this->sql_error($this->db_connection_id), $this->sql_errno($this->db_connection_id), $sql_explain, $line, $file);
}
else
***************
*** 143,419 ****
}
! //
! // sql_fetch_row
! //
! function sql_fetch_row($db_query_id = 0)
{
! if(! $db_query_id)
{
$db_query_id = $this->db_query_result;
}
!
! if( $this->db_row[$db_query_id] = @mysql_fetch_array($db_query_id))
! {
! return $this->db_row[$db_query_id];
! }
! else
! {
! return false;
! }
}
! //
! // sql_fetch_rowset
! //
! function sql_fetch_rowset($db_query_id = 0)
{
! if(! $db_query_id)
{
$db_query_id = $this->db_query_result;
}
- unset($this->db_row[$this->db_query_result]);
unset($this->db_rowset[$this->db_query_result]);
! while($this->db_rowset[$this->db_query_result] = @mysql_fetch_array($db_query_id))
{
! $rowset[] = $this->db_rowset[$db_query_id];
}
! return $rowset;
}
! //
! // sql_num_rows
! //
! function sql_num_rows($db_query_id = 0)
{
! if(! $db_query_id)
{
$db_query_id = $this->db_query_result;
}
! if( $this->db_row[$db_query_id] = @mysql_num_rows($db_query_id))
! {
! return $this->db_row[$db_query_id];
! }
! else
! {
! return false;
! }
}
! //
! // sql_insert_id
! //
! function sql_insert_id()
{
! if( $this->db_connection_id)
! {
! if( $result = @mysql_insert_id($this->db_connection_id))
! {
! return $result;
! }
! else
! {
! return false;
! }
! }
! else
{
! return false;
}
}
! //
! // sql_free_result
! //
! function sql_free_result($db_query_id = 0)
{
! if(! $db_query_id)
{
$db_query_id = $this->db_query_result;
}
- unset($this->db_row[$db_query_id]);
unset($this->db_rowset[$db_query_id]);
! if( @mysql_free_result($db_query_id))
! {
! return true;
! }
! else
! {
! return false;
! }
}
! //
! // sql_num_fields
! //
! function sql_num_fields($db_query_id = 0)
{
! if(! $db_query_id)
{
$db_query_id = $this->db_query_result;
}
! if( $result = @mysql_num_fields($db_connect_id))
! {
! return $return;
! }
! else
! {
! return false;
! }
}
! //
! // sql_field_name
! //
! function sql_field_name($db_query_id = 0, $field_offset)
{
! if(! $db_query_id)
{
$db_query_id = $this->db_query_result;
}
! if( $result = @mysql_fielf_name($db_query_id, $field_offset))
! {
! return $result;
! }
! else
! {
! return false;
! }
}
! //
! // sql_field_type
! //
! function sql_field_type($db_query_id = 0, $field_offset)
{
! if(! $db_query_id)
{
$db_query_id = $this->db_query_result;
}
! if( $result = @mysql_field_type($db_query_id, $field_offset))
! {
! return $result;
! }
! else
! {
! return false;
! }
}
! //
! // sql_fetch_field
! //
! function sql_fetch_field($db_query_id = 0, $field_row = -1, $field_name)
{
! if(! $db_query_id)
{
$db_query_id = $this->db_query_result;
}
! if( $field_row > -1)
{
! $result = @mysql_fetch_field($db_query_id, $field_row, $field_name);
}
else
{
! if( empty($this->db_row[$db_query_id]) && empty($this->db_rowset[$db_query_id]))
! {
! if( $this->sql_fetch_row($db_query_id))
! {
! $result = $this->db_row[$query_id][$field_name];
! }
! }
! else
! {
! if( $this->db_rowset[$db_query_id])
! {
! $result = $this->db_rowset[$db_query_id][$field_name];
! }
! else if( $this->db_row[$db_query_id])
! {
! $result = $this->db_row[$query_id][$field_name];
! }
! }
}
-
- return $result;
}
! //
! // sql_affected_rows
! //
function sql_affected_rows()
{
! if( $this->db_connection_id)
! {
! if( $result = @mysql_affected_rows($this->db_connection_id))
! {
! return $result;
! }
! else
! {
! return false;
! }
! }
! else
! {
! return false;
! }
! }
!
! //
! // sql_row_seek
! //
! function sql_row_seek($db_query_id = 0, $row)
! {
! if(! $db_query_id)
{
$db_query_id = $this->db_query_result;
}
! if( $result = @mysql_row_seek($db_query_id, $row))
! {
! return $result;
! }
! else
! {
! return false;
! }
}
! //
! // sql_error
! //
! function sql_error($db_query_id = 0)
{
! if(! $db_query_id)
{
! $db_query_id = $this->db_query_result;
}
! $result = @mysql_error($db_query_id);
! return $result;
}
! //
! // sql_errno
! //
! function sql_errno($db_query_id = 0)
{
! if(! $db_query_id)
{
! $db_query_id = $this->db_query_result;
}
! $result = @mysql_errno($db_query_id);
! return $result;
}
} // End of sql_db
--- 128,281 ----
}
! // Select a row as an Associative, Numeric or Both (array)
! function sql_fetch_row($db_query_id = NULL, $type = MYSQL_BOTH)
{
! if( is_null($db_query_id) )
{
$db_query_id = $this->db_query_result;
}
!
! return @mysql_fetch_array($db_query_id, $type);
}
! // Select all rows in one big array
! function sql_fetch_rowset($db_query_id = NULL, $type = MYSQL_BOTH)
{
! if( is_null($db_query_id) )
{
$db_query_id = $this->db_query_result;
}
unset($this->db_rowset[$this->db_query_result]);
! $this->db_rowset[$this->db_query_result] = Array();
!
! while($row = @mysql_fetch_array($db_query_id, $type))
{
! $this->db_rowset[$this->db_query_result][] = $row;
}
! return $this->db_rowset[$this->db_query_result];
}
! // Number of rows from the last select query. Shouldn't be used for
! // Firebird compatability (hopefully an ibase_num_rows function will
! // be soon)
! function sql_num_rows($db_query_id = NULL)
{
! if( is_null($db_query_id) )
{
$db_query_id = $this->db_query_result;
}
! return @mysql_num_rows($db_query_id);
}
! // Get last ID generated from an INSERT query
! function sql_insert_id($db_query_id = NULL)
{
! if( is_null($db_query_id) )
{
! $db_query_id = $this->db_query_result;
}
+
+ return @mysql_insert_id($this->db_connection_id);
}
! // Free result resource
! function sql_free_result($db_query_id = NULL)
{
! if( is_null($db_query_id) )
{
$db_query_id = $this->db_query_result;
}
unset($this->db_rowset[$db_query_id]);
! return @mysql_free_result($db_query_id);
}
! // Number of fields selected in last query
! function sql_num_fields($db_query_id = NULL)
{
! if( is_null($db_query_id) )
{
$db_query_id = $this->db_query_result;
}
! return @mysql_num_fields($db_query_id);
}
! // Name of a specific field from a result
! function sql_field_name($db_query_id = NULL, $field_offset)
{
! if( is_null($db_query_id) )
{
$db_query_id = $this->db_query_result;
}
! return @mysql_field_name($db_query_id, $field_offset);
}
! // Field type from a result
! function sql_field_type($db_query_id = NULL, $field_offset)
{
! if( is_null($db_query_id) )
{
$db_query_id = $this->db_query_result;
}
! return @mysql_field_type($db_query_id, $field_offset);
}
! // Gets column information and returns it object forum
! function sql_fetch_field($db_query_id = NULL, $field_offset = NULL)
{
! if( is_null($db_query_id) )
{
$db_query_id = $this->db_query_result;
}
! if( is_null($field_offset) )
{
! return @mysql_fetch_field($db_query_id);
}
else
{
! return @mysql_fetch_field($db_query_id, $field_offset);
}
}
! // Amount of rows affected in last query
function sql_affected_rows()
{
! if( is_null($db_query_id) )
{
$db_query_id = $this->db_query_result;
}
! return @mysql_affected_rows($this->db_connection_id);
}
! // SQL Error message from connection
! function sql_error($db_connection_id = NULL)
{
! if( is_null($db_connection_id) )
{
! $db_connection_id = $this->db_connect_id;
}
! return @mysql_error($db_connection_id);
}
! // SQL Error number from connection
! function sql_errno($db_connection_id = NULL)
{
! if( is_null($db_connection_id) )
{
! $db_connection_id = $this->db_connect_id;
}
! return @mysql_errno($db_connection_id);
}
} // End of sql_db
|