C
ChUrP
i'm trying to make a votum. for this a made two files: mysqldb.php and test.php.
mysqldb.php has all the functions for the connection to the sql server and querys.
if i start test.php i get this error message
Fatal error: Call to undefined function: query() in f:\apache\htdocs\test.php on line 6
what have i done wrong?
mysqldb.php has all the functions for the connection to the sql server and querys.
PHP:
<?php
class mysql_db
{
var $linkid = false;
var $resid = false;
var $doerror = false;
var $host = "localhost";
var $user = "user";
var $passwd = "passwd";
var $tables = "votum";
}
function connect()
{
$temp = @mysql_connect($this->host, $this->user, $this->passwd);
if(!$temp)
{
$this->echoerror();
return false;
}
$this->linkid = temp;
$temp = @mysql_select_db($this->tables, $temp);
if(!$temp)
{
$this->echoerror();
return false;
}
return $this->linkid;
}
function query($sql)
{
if(!$this->linkid)
{
if($this->doerror)
{
echo("<b>Nicht verbunden.</b><br>");
return false;
}
}
if($this->resid)
@mysql_free_result($this->resid);
$result = mysql_query($sql, $this->linkid);
if(!$result)
$this->echoerror();
$this->resid = $result;
return $result;
}
function echoerror()
{
if(!$this->doerror)
return;
if(!mysql_errno())
return;
echo("<font color=red><b>" . mysql_errno());
echo(": " . mysql_error() . "</b></font><br>");
}
function data()
{
if(!$this->linkid)
{
if($this->doerror)
{
echo("<b>Nicht verbunden</b>");
return false;
}
}
if(!$this->resid)
{
if($this->doerror)
{
echo("<b>Keine Abfrage</b>");
return false;
}
}
$result = mysql_array($this->resid, MYSQL_BOTH);
$this->echoerror();
return $result;
}
function echoquery($sql)
{
$this->query($sql);
echo("<table border=0 cellpadding=3><tr>");
$index = 0;
echo("<th>record</th>");
while($field = mysql_fetch_field($this->resid))
echo("<th>$field->name</th>");
echo("</tr>");
$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()
{
$this->connect();
}
$db = new mysql_db;
?>
with test.php i'm just testing the function
<?php
include("mysqldb.php");
$db->query("SELECT antwort,rot,bruen,blau FROM tbAntwort t1 INNER JOIN tbVotum t2 ON t2.votumid INNER JOIN tbFarbe t3 ON t3.farbnr=t1.antwortnr AND t3.besizterid=t2.besizterid WHERE t1.votenid=1");
while(list($antwort,$rot,$gruen,$blau) = $db->data())
echo("<span style=color: rgb($rot,$gruen,$blau)><b> $antwort </b></span><br>");
?>
if i start test.php i get this error message
Fatal error: Call to undefined function: query() in f:\apache\htdocs\test.php on line 6
what have i done wrong?