ich weis nicht wo der Fehler bei diesem Code ist:
cl_db_mysql.php
<?php
class db_mysql
{
PROTECTED $db_user;
PROTECTED $db_pass;
PROTECTED $db_server;
PROTECTED $insert_id;
PROTECTED $affected_rows;
PROTECTED $num_rows;
PROTECTED a dgen;
PUBLIC function __construct($datenbank)
{
if(!is_resource(self::$con))
{
self::$con = mysql_connect
($this->db_server,$this->db_user,$this->db_pass);
++self::$verbindungen;
}
mysql_select_db($datenbank, self::$con)
OR die('Fehler beim Verbinden zur Datenbank');
}
PUBLIC function prepare($var)
{
return mysql_real_escape_string($var);
}
PUBLIC function execute($sql)
{
++self::$queries;
$erg = mysql_query($sql, self::$con);
$this->affected_rows = mysql_affected_rows(self::$con);
$this->num_rows = @mysql_num_rows($erg);
if($this->num_rows)
{
$i=1;
while($array[$i] = mysql_fetch_assoc($erg)) {++$i;}
mysql_free_result($erg);
unset($array[$i]);
return $array;
}
$this->insert_id = mysql_insert_id(self::$con);
return true;
}
PUBLIC function insert_id()
{
return $this->insert_id;
}
PUBLIC function affected_rows()
{
return $this->affected_rows;
}
PUBLIC function num_rows()
{
return $this->num_rows;
}
PUBLIC function queries()
{
return self::$queries;
}
PUBLIC function verbindungen()
{
return self::$verbindungen;
}
}//Ende Klasse
?>
dazu gehört noch der code:
cl_db.php
<?php
class db extends db_mysql
{
PROTECTED $db_user ='*****';
PROTECTED $db_pass ='*****';
PROTECTED $db_server ='localhost';
PUBLIC function __construct($datenbank = '*')
{
parent::__construct($datenbank);
}
}
?>
weil wenn ich versuch die datei zu instarlieren
<?php
require('class/cl_db_mysql.php');
require('class/cl_db.php');
require('class/news.php');
$news = new news(1);
$news->install();
?>
kommt immer folgende Fehlermeldung im Browser:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /usr/export/www/vhosts/funnetwork/hosting/coegaming/class/cl_db_mysql.php on line 4
und diese Datei versuch ich zu instarlieren :
class einbruch extends Exception {
PUBLIC function __construct($message = FALSE,$code = FALSE)
{
parent::__construct($message,$code);
die('Die Seite wurde mit ungültigen Parametern aufgerufen. Dies
werten wir als Einbruchsversuch!<br>'.$this->getMessage());
}
}
class newsexception extends Exception {
PUBLIC function __construct($message = FALSE,$code = FALSE)
{ parent::__construct($message,$code); }
}
class datenfehler extends newsexception {
PUBLIC function __construct($message = FALSE,$code = FALSE)
{ parent::__construct($message,$code); }
}
class news
{
PROTECTED $anz_latest_news = 3;
PROTECTED $anz_news_liste = 5;
PROTECTED $table = "news1";
PROTECTED $latestnews = "startseite.php?";
PROTECTED $archivnews = "newsarchiv.php?";
PROTECTED $adminseite = "newsadmin.php?";
PROTECTED $link;
PROTECTED $felder =
array('news_admin','news_job','news_datum','news_titel','news_news','
news_links','news_timeak','news_ID','news_step','news_suche');
PROTECTED $modus = 1;
PROTECTED $auslesen = TRUE;
PROTECTED $message;
PUBLIC function __construct($modus)
{
$this->modus = $modus;
foreach($this->felder as $name)
{
if($_REQUEST[$name])
{ $this->$name = $_REQUEST[$name]; }
else { unset($this->$name); }
}
$this->test_1();
if(!$this->news_step) { $this->news_step = 0; }
Switch($this->modus)
{
case 1:
$this->link = $this->latestnews;
break;
case 2:
$this->link = $this->archivnews;
break;
case 3:
$this->link = $this->adminseite;
break;
}
}//Ende Konstruktor
PUBLIC function latest_news()
{
$ret ="<h3>News</h3>";
if($news=$this->news_liste(TRUE , FALSE))
{
$ret.=$news;
$ret.=$this->links();
}else{$ret.="<h4>Es liegen keine News vor</h4>";}
return $ret;
}
PUBLIC function archiv_news()
{
$ret ="<h3>Newsarchiv</h3>";
$ret.=$this->archiv_suche();
if($news=$this->news_liste(FALSE,FALSE))
{$ret.= $news;}else{$ret.="<h4>Es liegen keine News vor bzw.
entsprechen dem Suchkriterium.</h4>";}
return $ret;
}
PUBLIC function admin_news()
{
if($this->news_admin AND $this->news_job == 5000)
{
try
{
$this->test_2();
$this->speichern();
$this->message="News erfolgreich angelegt!";
}
catch(datenfehler $e)
{
$this->message = $e->getMessage()."<br>Bitte überprüfen Sie Ihre
Angaben!";
$this->auslesen = FALSE;
unset($this->news_admin);
}
}
if($this->news_admin AND $this->news_job == 1000 AND $this->news_ID)
{
try{
$this->test_2();
if($this->news_timeak == 1) {$this->news_datum_speichern = date('Y-m-d
H:i:s');}
$this->speichern($this->news_ID);
$this->message="News erfolgreich geändert!";
}
catch(datenfehler $e)
{
$this->message= $e->getMessage()."<br>News konnten nicht geändert
werden! Bitte kontrollieren Sie Ihre Angaben.";
$this->auslesen = FALSE;
unset($this->news_admin);
}
}
if($this->news_job == 2000 AND $this->news_ID)
{
try
{
$this->weg($this->news_ID);
$this->message="News erfolgreich gelöscht!";
$this->news_step = 0;
}
catch(datenfehler $e)
{
$this->message= $e->getMessage();
}
}
$ret.="<h3>News Adminbereich</h3>";
$ret.=$this->links();
if($this->message)
{ $ret.="<h4><font color=\"red\">".$this->message."</font></h4>"; }
if(!$this->news_admin AND $this->news_job == 5000)
{
$this->news_datum = date('d-m-Y H:i:s');
$ret.="<h4>Eine neue News anlegen</h4>";
$ret.=$this->news_form(5000,$this->news_datum,False);
}
if(!$this->news_admin AND $this->news_job == 1000 AND $this->news_ID)
{
if($this->auslesen)//werte setzen
{
$db=new db();
$erg=$db->execute("SELECT ID, titel, news, DATE_FORMAT(datum,'%d-%m-
%Y %T') as zeit, links FROM ".$this->table." WHERE ID = '".$this-
>news_ID."'");
$this->news_datum = $erg[1]['zeit'];
$this->news_titel = $erg[1]['titel'];
$this->news_news = $erg[1]['news'];
$this->news_links = $erg[1]['links'];
unset($erg);unset($db);
}
$ret.="<h4>Die News vom ".$this->news_datum." bearbeiten</h4>";
$ret.=$this->news_form(1000,$this->news_datum,$this->news_ID);
}
$ret.="<h4>Liste der News</h4>";
$ret.=$this->news_liste(FALSE,TRUE);
return $ret;
}
PRIVATE function speichern($ID = FALSE)
{
if($ID)
{
$sql="UPDATE ".$this->table." SET datum = '".$this-
>news_datum_speichern."', titel = '".$this->news_titel."', news =
'".$this->news_news."', links = '".$this->news_links."' WHERE ID =
'".$ID."'";
$db=new db();
$erg=$db->execute($sql);
}
else
{
$sql="INSERT INTO ".$this->table." (datum, titel, news, links) VALUES
('".$this->news_datum_speichern."','".$this->news_titel."','".$this-
>news_news."','".$this->news_links."')";
$db=new db();
$erg=$db->execute($sql);
if(!($db->insert_id() >0 ))
{ throw new datenfehler('Datensatz konnte nicht gespeichert
werden.'); }
}
}
PRIVATE function weg($ID = FALSE)
{
if($ID)
{
$sql="DELETE FROM ".$this->table." WHERE ID = '".$ID."'";
$db=new db();
$erg=$db->execute($sql);
if($db->affected_rows()!=1){throw new datenfehler('News konnte nicht
gelöscht werden.');}
}
else
{
throw new datenfehler('Keine News zum Löschen ausgesucht.');
}
}
PRIVATE function links()
{
$trennzeichen ="* ";
$ret="<p>";
if($this->modus!=1 ){$ret.="<a href=\"".$this->latestnews."\">Zu den
aktuellen Meldungen</a> ".$trennzeichen;}
if($this->modus!=2){$ret.=" <a href=\"".$this->archivnews."\">Zum
Newsarchiv</a> ".$trennzeichen;}
if($this->modus==3)
{$ret.="<a href=\"".$this->adminseite."news_job=5000\">Neue News
anlegen</a> ".$trennzeichen;}
$ret=substr($ret,0,-Strlen($trennzeichen) );
$ret.="</p>";
return $ret;
}
PRIVATE function news_form($job,$time, $ID = False)
{
$ret.="<form action=\"".$this->adminseite."\" method=\"post\">";
$ret.="<input type=\"hidden\" name=\"news_job\" value=\"".$job."\">";
$ret.="<input type=\"hidden\" name=\"news_step\" value=\"".$this-
>news_step."\">";
if($ID)
{ $ret.= "<input type=\"hidden\" name=\"news_ID\"
value=\"".$ID."\">"; }
$ret.="
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"
align=\"center\" width=\"100%\">
<tr>
<td>Datum:</td>
<td><input type=\"text\" value=\"".htmlentities($time)."\"
name=\"news_datum\" size=\"35\"></td>
</tr>
<tr>";
if($job==1000)
{
$ret.="
<tr>
<td> </td>
<td><input type=\"checkbox\" value=\"1\" name=\"news_timeak\">
Aktuelle Zeit verwenden</td>
</tr>";}
$ret.="
<tr>
<td valign=\"top\">Titel:</td>
<td><input type=\"text\" value=\"".htmlentities($this-
>news_titel)."\" name=\"news_titel\" size=\"35\"></td>
</tr>
<tr>
<td valign=\"top\">News:</td>
<td><textarea name=\"news_news\" cols=\"40\"
rows=\"10\">".htmlentities($this->news_news)."</textarea></td>
</tr>
<tr>
<td valign=\"top\">Links:<br>(durch Kommata trennen)</td>
<td><textarea name=\"news_links\" cols=\"40\"
rows=\"3\">".htmlentities($this->news_links)."</textarea></td>
</tr>
<tr>
<td> </td>
<td><input type=\"submit\" name=\"news_admin\" value=\"Speichern\"></
td>
</tr>
</table></form><hr>";
return $ret;
}
PRIVATE function archiv_suche()
{
$ret.="<h4>Volltextsuche (mindestens 4 Zeichen) ";
$ret.="<form action=\"".$this->link."\" method=\"post\">";
$ret.="<input type=\"text\" name=\"news_suche\"
value=\"".htmlentities($this->news_suche)."\">";
$ret.="<input type=\"submit\" name=\"news_suche1\"
value=\"Suchen\"></form></h4>";
return $ret;
}
PRIVATE function news_liste($latestnews = False,$admin = FALSE)
{
if($latestnews) { $anz = $this->anz_latest_news; } else { $anz =
$this->anz_news_liste; }
$db=new db();
$sql1="SELECT count(*) as anz FROM ".$this->table." ";
if($this->news_suche != "")
{
$sql1.=" WHERE MATCH (titel, news) AGAINST ('".$db->prepare($this-
>news_suche)."') ";
$suche="news_suche=".urlencode($this->news_suche)."&";
}
$erg1=$db->execute($sql1);
if(!$latestnews) { $schalter=$this->step($anz, $erg1[1]['anz'],
$this->link.$suche); }
unset($db);unset($erg1);
$db=new db();
$sql1="SELECT ID, news, titel, DATE_FORMAT(datum,'%d-%m-%Y %T') as
zeit, links FROM ".$this->table." ";
if($this->news_suche != "")
{ $sql1.=" WHERE MATCH (titel, news) AGAINST ('".$db->prepare($this-
>news_suche)."') "; }
else
{ $sql1.=" ORDER BY datum DESC "; }
$sql1.=" LIMIT ".($this->news_step*$anz).",".$anz." ";
$erg=$db->execute($sql1);
if($db->num_rows() > 0)
{
if($schalter){$ret.="<hr>".$schalter."<hr>";}
foreach($erg as $zeile)
{
$ret.="
<p><font color=red>".htmlentities($zeile['zeit'])."</font>
<br><b>". htmlentities ($zeile['titel'])."</
b><br>".nl2br(htmlentities($zeile['news']))."<br>";
if($zeile['links']!="")
{
$ret.="";
$links = explode(",",$zeile['links']);
foreach($links as $link)
{
$ret.="<a href='".$link."' target='_blank'>".$link."</a><br>";}
}
if($admin)
{
$ret.="<br><a href=\"".$this->adminseite."news_ID=".$zeile['ID']."&news_job=1000&news_step=".$this
->news_step."\">bearbeiten</a> -- ";
$ret.="<a href=\"".$this-
>adminseite."news_ID=".$zeile['ID']."&news_job=2000&news_step=".$this
->news_step."\">löschen</a><br>";
}
$ret.="<hr>";
}
$ret.=$schalter;
return $ret;
}
else{return FALSE;}
}
PRIVATE function step($anz, $maxanzahl, $link)
{
$text="<p>In den News blättern: ";
if($this->news_step == 0 AND $maxanzahl<=$anz){return FALSE;}
if($this->news_step == 0 AND $maxanzahl>$anz)//Nur weiter
{
return $text."<a href=\"".$link."news_step=".($this-
>news_step+1)."\">weiter</a>";
}
if($this->news_step !=0 AND $maxanzahl<=$anz*($this->news_step+1))
{
return $text."<a href=\"".$link."news_step=".($this->news_step-
1)."\">zurück</a>";
}
return
$text."<a href=\"".$link."news_step=".($this->news_step-
1)."\">zurück</a> --
<a href=\"".$link."news_step=".($this->news_step+1)."\">weiter</a></
p>";
}
PRIVATE function test_1()
{
$testarray= array(5000,2000,1000);
if($this->news_job AND !in_array($this->news_job ,$testarray)){throw
new einbruch('Einbruch über news_job.');}
$muster="^[0-9]{1,5}$";
if($this->news_step AND !ereg($muster,$this->news_step)){throw new
einbruch('Einbrüch über news_step.');}
$muster="^[0-9]{1,20}$";
if($this->news_ID AND !ereg($muster,$this->news_ID)){throw new
einbruch('Einbruch über news_ID.');}
if($this->news_timeak AND $this->news_timeak != 1){throw new
einbruch('Einbruch über news_timeak.');}
if($this->news_admin AND $this->news_admin != 'Speichern')
{throw new einbruch;}
}
PRIVATE function test_2()
{
if($this->news_timeak != 1 AND !($this->news_datum_speichern = $this->testdate($this->news_datum)))
{throw new datenfehler("Das Datum stimmt nicht!");}
}
PRIVATE function testdate($datumorg = FALSE)
{
if(!$datumorg){return TRUE;}
$date=explode(" ",$datumorg,2);
$datum=explode("-",$date[0],3);
if(@checkdate($datum[1],$datum[0],$datum[2]))
{
return $datum[2]."-".$datum[1]."-".$datum[0]." ".$date[1];
}
return False;
}
PUBLIC function install()
{
$db=new db();
$db->execute(
"CREATE TABLE ".$this->table." (
ID int(10) unsigned NOT NULL auto_increment,
datum datetime NOT NULL default '0000-00-00',
titel varchar(60) collate latin1_german1_ci default NULL,
news mediumtext collate latin1_german1_ci,
links varchar(255) collate latin1_german1_ci default NULL,
PRIMARY KEY (ID),
FULLTEXT KEY titel (titel,news)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci
COMMENT='Tabelle fuer Newssystem';");
}
}


