Guten Morgen.
Der Tipp von Meikel mit den Nested-Sets-Modell hat mir sehr geholfen, denn es ist sehr viel besser als das vorher von mir verwendete Parent-Modell. Es ist schneller und erlaubt zudem ein genaueres Ranking der Äste.
Jedoch hilft mir das nicht wirklich bei meiner Datenbankklasse weiter. Ich würde euch bitten mir Tipps zu geben, welche Fehlerquellen ich beachten muss und dementsprechend eine Fehlermeldung ausgeben muss. Ein bisschen etwas habe ich in den letzten zwei Tagen schon geschafft. Habe non-stop drangesessen.
PHP-Code:
<?php
class DbConnector {
/* DATABASE VARIABLES */
var $host = "localhost";
var $user = "user";
var $password = "pwd";
var $dbname = "dbname";
/* VARIABLES */
var $result;
var $theQuery;
var $link;
var $result_number;
var $db_status = "disconnected";
var $errormessage = "";
var $errornumber = 0;
/* CATCH DATABASE VARS */
function DbConnector($host,$user,$pw,$dbname) {
$this->host = $host;
$this->user = $user;
$this->password = $pw;
$this->dbname = $dbname;
$this->db_open();
}
/* CONNECT TO DATABASE */
function db_open() {
if($this->db_status != "connected") {
if(!($this->link = mysql_connect($this->host, $this->user, $this->password))) {
$this->db_status = "disconnected";
$this->errormessage .= mysql_error() ."\n";
$this->errornumber .= mysql_errno() ."\n";
$this->password = "******";
return 0;
}
else {
$this->db_status = "connected";
$this->db_select_db($this->dbname);
$this->password = "******";
return 1;
}
}
else {
echo "Critical ERROR: DB is used 2 times";
$this->password = "******";
return 0;
}
}
/* SELCT DATABASE */
function db_select_db($dbname) {
if($this->db_status == "connected") {
if(!mysql_select_db($dbname)) {
$this->errormessage .= "Could not select database: ".mysql_error() ."\n";
$this->errornumber .= mysql_errno() ."\n";
return 0;
}
else return 1;
}
else return 0;
}
/* CHECK CONNECTION */
function is_connected() {
return($this->db_status == "connected");
}
/* EXECUTE DATABASE QUERY */
function db_query($query) {
$this->theQuery=$query;
if($this->db_status == "connected") {
if(!$this->result = mysql_query($query)) {
$this->errormessage .= mysql_error() ."\n";
$this->errornumber .= mysql_errno() ."\n";
return 0;
}
else {
$query = trim($query);
if(substr(strtoupper($query), 0, 4) == "SELE") $this->result_number = mysql_affected_rows($this->result);
return 1;
}
}
else return 0;
}
/* RETURNS LATEST DATABASE QUERY */
function getQuery() {
return $this->theQuery;
}
/* RETURN ROW COUNT */
function getNumRows($result){
return mysql_num_rows($result);
}
/* GET ARRAY OF QUERY RESULTS */
function db_save_results($typ = 0) {
$array = array();
while ($result = $this->db_get_next_result($typ)) $array[] = $result;
return $array;
}
/* GET NEXT RESULT OF LAST QUERY */
function db_get_next_result($typ = 0) {
if(!$this->result) {
$this->errormessage .= "Result is empty.\n";
$this->errornumber .= 99 ."\n";
return 0;
}
else {
if($typ == 0) return mysql_fetch_array($this->result);
if($typ == 1) return mysql_fetch_row ($this->result);
if($typ == 2) return mysql_fetch_assoc($this->result);
}
}
/* GET LAST ERRORS */
function db_get_last_error() {
if($this->errornumber != "" || $this->errormessage != "")
return ($this->errornumber . " : " . $this->errormessage);
else return "";
}
/* CLOSE CONNECTION */
function close() {
if($this->db_status == "connected") {
if(!mysql_close($this->link)) {
$this->errornumber .= mysql_errno() ."\n";
$this->errormessage .= mysql_error() ."\n";
$this->password = "******";
return 0;
}
else {
$this->db_status = "disconnected";
$this->password = "******";
return 1;
}
}
else {
$this->password = "******";
return 0;
}
}
}
?>
Wäre euch für Hilfe und Hinweise sehr dankbar!
MfG, Andy