ich weis nicht wo der Fehler bei diesem Code ist:
cl_db_mysql.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | <?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
1 2 3 4 5 6 7 8 9 10 11 12 | <?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
1 2 3 4 5 6 7 | <?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 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | 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';"); } } |