Frage zu Datenbank-Klasse (damals hier gefunden)

pxlArtizzt

Erfahrenes Mitglied
Hallo allerseits!

ich nutze schon seit einiger Zeit diese Datenbank-Klasse, welche ich seinerzeit auch hier gefunden habe (ein wenig Recherche ergab, dass sie von Johannes Röttger stammte)...

PHP:
class db {

// integer
	var $a_rows = 0;
	var $link_id = 0;
	var $query_id = 0;
	var $errno = 0;
	var $show_error = 0;
	var $mail_error = 0;
	var $port = 0;
	var $query_c = 0;
	var $rows = 0;
// string
	var $errdesc = '';
	var $hostname = '';
	var $username = '';
	var $password = '';
	var $database = '';
	var $techmail = '';
// array 
	var $record = array();


		function connect() {
			if ($this->link_id == 0) {
				if ( ereg(':',$this->hostname) ) {
					list($host,$port) = explode(':',$this->hostname);
					$this->port = $port;
				} else {
					$this->port = 3306;
				}
				$this->link_id = @mysql_connect($this->hostname.':'.$this->port,$this->username,$this->password);
				if ( !$this->link_id ) {
					return('no_connect');
				}
				if ($this->database != '') {
					$this->select_db($this->database);
				}
			}
		}


		function select_db( $database = '' ) {
			if ($database != '') {
				$this->database = $database;
			}
			if( !@mysql_select_db($this->database, $this->link_id) ) {
				$this->error("cannot use database ".$this->database);
			}
		}


		function query( $query ) {
			$this->query_id = @mysql_query( $query, $this->link_id );
			$this->query_c++;
			if ( !$this->query_id ) {
				$this->error("Invalid SQL: \"<i>$query</i>\"");
			}
			$this->a_rows = @mysql_affected_rows($this->query_id);
			return $this->query_id;
		}


		function fetch_row( $query_id = -1 ) {
			if ( $query_id != -1) {
				$this->query_id = $query_id;
			}
			$this->record = @mysql_fetch_row( $this->query_id );
			return $this->record;
		}


		function fetch_array( $query_id = -1 ) {
			if ( $query_id != -1) {
				$this->query_id = $query_id;
			}
			$this->record = @mysql_fetch_array( $this->query_id );
			return $this->record;
		}


		function fetch_object( $query_id = -1 ) {
			if ( $query_id != -1) {
				$this->query_id = $query_id;
			}
			$this->record = @mysql_fetch_object( $this->query_id );
			return $this->record;
		}


		function quote($value) {
			return "'". preg_replace("/'/", "''", $value) ."'";
		}


		function free_result ($query_id = -1) {
			if ($query_id != -1) {
				$this->query_id = $query_id;
			}
			return mysql_free_result ($this->query_id);
		}


		function num_rows($query_id = -1) {
			if ($query_id != -1) {
				$this->query_id = $query_id;
			}
			return mysql_num_rows ($this->query_id);
		}


		function insert_id() {
			return mysql_insert_id ($this->link_id);
		}


		function stats($print = 0) {
			if ($print == 0) {
				return $this->query_c;
			} else {
				print ($this->query_c);
			}
		}


		function error() {
			$this->errdesc = mysql_error();
			$this->errno = mysql_errno();
			$message = "Error&nbsp;&nbsp;&nbsp;: $this->errdesc (#$this->errno)<br />\n";
			$message.= "Date&nbsp;&nbsp;&nbsp;&nbsp;: ".date("D, F j, Y H:i:s")."<br />\n";
			$message.= "Script&nbsp;&nbsp;: ".$_SERVER["REQUEST_URI"]."<br />\n";
			$message.= "IP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: ".$_SERVER["REMOTE_ADDR"]."<br />\n";
			$message.= "Host&nbsp;&nbsp;&nbsp;&nbsp;: ".gethostbyaddr($_SERVER["REMOTE_ADDR"])."<br />\n";
			$message.= "Querys&nbsp;&nbsp;: ".$this->query_c."<br />\n";
			if ($this->show_error == 1) {
				print("
					<table width=\"700\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">
						<tr>
							<td width=\"700\" style=\"font-family:Tahoma;font-size:8pt;letter-spacing:1px;background:#ffffff;\">$message</td>
						</tr>
					</table>");
			}
			if ($this->mail_error == 1) {
				@mail($this->techmail,"mySQL::error",$message,"From: X-Mailer");
			}
		}

	}  // end class



sooo, was ich aber nicht herausfinden konnte ist, wie ich damit zu 2 Datenbanken verbinde und die SQL-Queries dahingehend schreiben muss... Vielen Dank für Eure Hilfen schonmal! :)
 

Neue Beiträge

Zurück