Hallo,
ich hab ein Problem und zwar wollte ich mir eine mysqli Klasse schreiben, ich weiß es gibt genug Klassen, aber ich hab schon meine Gründe dafür...
Nun habe ich aber ein Problem, ich bekomm immer folgenden Fehler:
Fatal error: Call to undefined method mysqli::fetch_array() in C:\xampp\htdocs\database.php on line 54
Hier ist mein Code:
Nicht wundern, es ist natürlich noch nicht fertig, aber das mache ich noch. Mein Problem ist eigentlich alle Einträge aus der DB zu bekommen.
Kann mir bitte jemand helfen?
Danke
lg Alex
ich hab ein Problem und zwar wollte ich mir eine mysqli Klasse schreiben, ich weiß es gibt genug Klassen, aber ich hab schon meine Gründe dafür...
Nun habe ich aber ein Problem, ich bekomm immer folgenden Fehler:
Fatal error: Call to undefined method mysqli::fetch_array() in C:\xampp\htdocs\database.php on line 54
Hier ist mein Code:
PHP-Code:
<?php
class Database extends mysqli {
public function __construct($host, $user, $pass, $db)
{
$this->connect($host, $user, $pass, $db);
}
public function connect($host, $user, $pass, $db)
{
try {
parent::__construct($host, $user, $pass, $db);
} catch (DBException $e) {
die($e);
}
}
/**
* escape a string
*
* @param string $str
* @return string the escaped string
**/
protected function escapeString($str) {
$escaped = parent::real_escape_string($str);
return $escaped;
}
public function query($sql) {
// make sure that $sql is not empty
if($sql)
{
// check if $sql is an insert, update, delete
if(preg_match("/^(insert|update|delete)\s+/i",$sql))
{
/*
if(mysql_query($sql)) {
return true;
}
else {
return mysql_error();
}
*/
}
// check if $sql is a select
elseif(preg_match("/^(select)\s+/i",$sql))
{
$result = parent::query($sql);
while($row = parent::fetch_array($result))
{
$obj = $row;
}
return $obj;
}
}
}
/**
* build the query to find all entries from one table
*
* @param string $table - the name of the table
* @param array $where - where clause
* @param array $order - sort order
* @return string a full query
**/
public function findAll($table, $where = NULL, $order = NULL) {
if($table) {
$query = 'SELECT * FROM '.$table.' ';
if($where) {
$query .= 'WHERE '.$where;
}
if($order) {
$query .= ' ORDER BY '.$order;
}
$result = $this->query($query);
return $result;
}
}
public function __destruct() {
parent::close();
}
}
$db = new Database(...);
print_r($db->findAll('dc_pages'));
?>
Kann mir bitte jemand helfen?
Danke
lg Alex
Kommentar