hi, ich habe einige versuche mit datenbank auslesen gemacht! ich habe mir ein kleines script geschrieben was daten auslesen soll und anschließen in einer tabelle ausgeben soll! jedoch kommt immer wieder dieser fehler!
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /home/www/web51/html/mysqldb.php on line 121
Fatal error: Call to a member function on a non-object in /home/www/web51/html/1test.php on line 3
ich hab eine Klassendatei, die so aussieht:
<?php
class mysql_db {
var $link = false;
var $resid = false;
var $doerror = false;
var $host = "127.0.0.1";
var $user = "web51";
var $passwd = "***";
var $tables = "usr_web51_1";
function connect()
// Verbindet zur Datenbank
{
$temp = @mysql_connect
($this->host, $this->user, $this->passwd);
if (!$temp)
{
$this->echoerror();
return false;
}
$this->link = $temp;
$temp = @mysql_select_db($this->tables, $temp);
if (!$temp)
{
$this->echoerror();
return false;
}
return $this->link;
}
function query($sql)
// Sendet eine Anfrage an die Datenbank
{
if (!$this->link)
{
if ($this->doerror)
{
echo ("<b>Nicht verbunden.</b><br>");
return false;
}
}
if ($this->resid) @mysql_free_result($this->resid);
$result = mysql_query($sql, $this->link);
if (!$result) $this->echoerror();
$this->resid = $result;
return $result;
}
function echoerror()
// erzeugt eine Fehlerausschrift
// wenn $doerror=TRUE
{
if (!$this->doerror) return;
if (!mysql_errno()) return;
echo ("<font color=\"red\"><b>" . mysql_errno());
echo (": ". mysql_error() ." </b></font><br>");
}
function data()
// liefert einen Datensatz
{
if (!$this->link)
{
if ($this->doerror)
echo ("<b>Nicht verbunden!</b><br>");
return false;
}
if (!$this->resid)
{
if ($this->doerror)
echo ("<b>Keine Abfrage!</b><br>");
return false;
}
$result = mysql_fetch_array($this->resid, MYSQL_BOTH);
$this->echoerror();
return $result;
}
function echoquery($sql)
//Fragt die Datenbank ab und stellt die Abfrage dar
{
$this->query($sql);
echo("<table border cellpadding=\"3\"><tr>");
$index = 0;
echo("<th>record</th>");
while ($field = mysql_fetch_field($this->resid))
echo("<th>$field->name</th>");
echo ("</tr>\n");
$rec=0;
while ($row = $this->data())
{
$rec++;
echo("<tr><td>$rec</td>");
for ($i=0; $i<mysql_num_fields($this->resid); $i++)
echo("<td>".htmlentities($row[$i])." </td>");
echo("</tr>\n");
}
echo ("</table>");
}
function set_doerror($boolvalue)
{
$this->doerror = $boolvalue;
}
function mysql_db()
// Construktor
{
$this->connect();
}
db = new mysql_db;
?>
diese heißt mysqldb.php
dann hab ich eine datei 1test.php, die so aussieht!
<?php
include("mysqldb.php");
$db->echoquery("select * from vofarbe");
?>
was soll passieren? es soll die tabelle vofarben in der datenbank usr_web51_1 auslesen und in einer tabelle darstellen! ich habe die listings aus einem buch! in dem buch sind eine menge beispiele, mit diesem script und es funktioniert auch! was kann ich machen?
johnpatcher
Lesezeichen