Fejl: cannot redeclare class mysql_class
Er der nogen der kan hjælpe mig med en function. Jeg kan kalde den en gang men anden gang får jeg en fejl om at jeg ikke kan redeklarer klassen, jeg må have kikket mig blind på den.Jeg har en masse tabeller der ser ens ud men hedder ikke det samme og har ikke det samme indhold.
<?php
require("PHP_Class.php");
$sql = new MySQL_class;
$sql->Create("blabla");
function get_tabel($tabelname) {
global $sql;
echo("<table>\n");
echo("<tr><th>Art.nr</th><th>Produkt</th><th>Kg/kartong</th></tr>\n");
$sql->Query("Select * from $tabelname ORDER BY text");
for ($i = 0; $i < $sql->rows; $i++) {
$sql->Fetch($i);
$artNr = $sql->data[0];
$text = $sql->data[1];
$antalKg = $sql->data[2];
echo("<tr><td>$artNr</td><td>$text</td><td>$antalKg</td></tr>\n");
}
}
echo("</table>\n");
?>
OBS Dette er klasse jeg har "lånt"
<?
class MySQL_class {
var $db, $id, $result, $rows, $data, $a_rows;
var $user, $pass, $host;
/* Make sure you change the USERNAME and PASSWORD to your name and
* password for the DB
*/
function Setup ($user, $pass) {
$this->user = $user;
$this->pass = $pass;
}
function Create ($db) {
if (!$this->user) {
$this->user = "blabla";
}
if (!$this->pass) {
$this->pass = "blabla";
}
$this->db = $db;
$this->id = @mysql_pconnect($this->host, $this->user, $this->pass) or
MySQL_ErrorMsg("Unable to connect to MySQL server: $this->host : '$SERVER_NAME'");
$this->selectdb($db);
}
function SelectDB ($db) {
@mysql_select_db($db, $this->id) or
MySQL_ErrorMsg ("Unable to select database: $db");
}
# Use this function is the query will return multiple rows. Use the Fetch
# routine to loop through those rows.
function Query ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->id);
}
# Use this function if the query will only return a
# single data element.
function QueryItem ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->id);
$this->data = @mysql_fetch_array($this->result) or
MySQL_ErrorMsg ("Unable to fetch data from query: $query");
return($this->data[0]);
}
# This function is useful if the query will only return a
# single row.
function QueryRow ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->id);
$this->data = @mysql_fetch_array($this->result) or
MySQL_ErrorMsg ("Unable to fetch data from query: $query");
return($this->data);
}
function Fetch ($row) {
@mysql_data_seek($this->result, $row) or
MySQL_ErrorMsg ("Unable to seek data row:
$row");
$this->data = @mysql_fetch_array($this->result) or
MySQL_ErrorMsg ("Unable to fetch row: $row");
}
function Insert ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform insert: $query");
$this->a_rows = @mysql_affected_rows($this->id);
}
function Update ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform update: $query");
$this->a_rows = @mysql_affected_rows($this->id);
}
function Delete ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform Delete: $query");
$this->a_rows = @mysql_affected_rows($this->id);
}
}
?>
