Hi,
ich habe folgende Klasse aus dem Internet herunter geladen:
Wie spreche ich diese Klasse nun an, wenn ich z.B. die Spalte "de" der Tabelle "uebersetzung" als array haben möchte?
Wer versteht diese Klasse? :-)
Danke!!!!!!!!!!!!!!!!!!!!!!!
ich habe folgende Klasse aus dem Internet herunter geladen:
PHP-Code:
<?php
class Mysql4db
{
// These Variables defined in config file
var $dbHost;
var $dbUser;
var $dbPassword;
var $dbName;
var $db_link_ptr;
var $tables;
var $fields;
var $classname = "Mysql4db";
var $db_result;
var $db_affected_rows;
var $saved_results = array();
var $results_saved = 0;
function Mysql4db($create = "", $dbHost, $dbUser, $dbPassword, $dbName)
{
$this->db_link_ptr = @mysql_connect($dbHost, $dbUser, $dbPassword) or
$this->error("", mysql_error(), mysql_errno());
$this->dbhandler = @mysql_select_db($dbName);
$this->dbHost = $dbHost;
$this->dbUser = $dbUser;
$this->dbPassword = $dbPassword;
$this->dbName = $dbName;
if (!$this->dbhandler)
{
if ($create == "1")
{
@mysql_create_db($dbName, $this->db_link_ptr) or $this->error("Database can not be created.",mysql_error(),mysql_errno());;
$this->dbhandler = @mysql_select_db($db);
}
}
}
function error($where = "", $error, $errno)
{
echo "$where<br />";
die($error."<br />".$errno);
}
function error_msg()
{
return mysql_error();
}
function PushResults()
{
$this->saved_results[$this->results_saved] = array($this->db_result,$this->db_affected_rows);
$this->results_saved++;
}
function PopResults()
{
$this->results_saved--;
$this->db_result = $this->saved_results[$this->results_saved][0];
$this->db_affected_rows = $this->saved_results[$this->results_saved][1];
}
function reselect_db($db)
{
$this->dbhandler = @mysql_select_db($db);
}
function closeDB()
{
@mysql_close($this->db_link_ptr);
}
function create_table($tblName, $tblStruct)
{
if (is_array($tblStruct)) {
$theStruct = implode(",", $tblStruct);
} else {
$theStruct = $tblStruct;
@mysql_query("create table $tblName ($theStruct)") or $this->error("create table $tblName ($theStruct)",mysql_error(),mysql_errno());
}
}
function drop_table($tblName)
{
@mysql_query("drop table if exists $tblName") or $this->error("drop table $tblName",mysql_error(),mysql_errno());
}
function raw_query($sql_stat)
{
$this->db_result = @mysql_query($sql_stat) or $this->error($sql_stat,mysql_error(),mysql_errno());
$this->db_affected_rows = @mysql_num_rows($this->db_result);
}
function count_records($table, $filter = "")
{
$this->db_result = @mysql_query("select count(*) as num from $table".(($filter!="")?" where $filter" : ""));
$xx=@mysql_result($this->db_result, 0, "num");
return $xx;
}
function select($fields, $tables, $where = "", $order_by = "", $group_by = "", $having = "", $limit = "")
{
$sql_stat = "SELECT $fields FROM $tables ";
if (!empty($where))
{
$sql_stat .= "WHERE $where ";
}
if (!empty($group_by))
{
$sql_stat .= "GROUP by $group_by ";
}
if (!empty($order_by))
{
$sql_stat .= "ORDER BY $order_by ";
}
if (!empty($having))
{
$sql_stat.="HAVING $having ";
}
if (!empty($limit))
{
$sql_stat.="LIMIT $limit ";
}
$this->db_result = @mysql_query($sql_stat) or $this->error($sql_stat, mysql_error(), mysql_errno());
$this->db_affected_rows = @mysql_num_rows($this->db_result);
return $sql_stat;
}
function list_tables()
{
$this->db_result = @mysql_list_tables($this->dbName);
$this->db_affected_rows = @mysql_num_rows($this->db_result);
return $this->db_result;
}
function describe($tablename)
{
$this->result = @mysql_query("describe $tablename");
}
function table_exists($tablename)
{
$this->pushresults();
$description=$this->describe($tablename);
$this->popresults();
if ($description) $exists = true; else $exists=false;
return $exists;
}
function tablename($tables, $tbl)
{
return mysql_tablename($tables,$tbl);
}
function insert_id()
{
return mysql_insert_id();
}
function insert($table, $fields = "", $values = "")
{
$sql_stat = "INSERT INTO $table ";
if (is_array($fields))
{
$theFields = implode(",", $fields);
}
else
{
$theFields = $fields;
}
if (is_array($values)) {
$theValues = "'".implode("','",$values)."'";
} else {
$theValues=$values;
}
$theValues = str_replace("'now()'", "now()", $theValues);
if (!empty($theFields)) $sql_stat .= "($theFields) ";
$sql_stat .= "values ($theValues)";
@mysql_query($sql_stat) or $this->error($sql_stat,mysql_error(),mysql_errno());
}
function update($table, $newvals, $where="")
{
if (is_array($newvals))
{
$theValues = implode(",", $newvals);
}
else
{
$theValues=$newvals;
}
$sql_stat = "update $table set $theValues";
if (!empty($where))
{
$sql_stat.=" where $where";
}
@mysql_query($sql_stat) or $this->error($sql_stat, mysql_error(), mysql_errno());
}
function delete($table, $where = "")
{
$sql_stat = "delete from $table ";
if (!empty($where))
{
$sql_stat .= "where $where ";
}
$db_result2 = @mysql_query($sql_stat) or $this->error($sql_stat, mysql_error(), mysql_errno());
$this->db_affected_rows = @mysql_affected_rows($this->db_result2);
}
function free()
{
@mysql_free_result($this->db_result) or $this->error("", mysql_error(), mysql_errno());
}
function fetch_row()
{
$row = mysql_fetch_row($this->db_result);
return $row;
}
function result($recno,$field)
{
return mysql_result($this->db_result, $recno, $field);
}
function num_fields()
{
return mysql_num_fields($this->db_result);
}
function fetch_array()
{
$row = mysql_fetch_array($this->db_result);
return $row;
}
function fetch_field()
{
$row = mysql_fetch_field($this->db_result);
return $row;
}
}
?>
Wie spreche ich diese Klasse nun an, wenn ich z.B. die Spalte "de" der Tabelle "uebersetzung" als array haben möchte?
Wer versteht diese Klasse? :-)
Danke!!!!!!!!!!!!!!!!!!!!!!!
EDIT:
PHP-Tags by TBT
Kommentar