Hallo,
Ich habe mir eine schöne MySQL classe geschrieben, leider funktioniert das mysql_num_rows nicht.
Also, Das geht nicht:
Hat jemand rat?
//EDIT:
Also es wird immer 0 ausgegeben, auch wenn in der DB einträge vorhanden sind.
Ich habe mir eine schöne MySQL classe geschrieben, leider funktioniert das mysql_num_rows nicht.
PHP-Code:
<?php
class db {
//Desifne variables
var $host = 'localhost';
var $user = '***';
var $pass = '***';
var $data = '***';
var $link = NULL;
var $query = NULL;
var $result = NULL;
function connect() {
//Function connect
if(!$this->link = @mysql_connect($this->host,$this->user,$this->pass)) {
//If not connected DB
die('Could not connect to the database: '.mysql_error());
}
if(!@mysql_select_db($this->data,$this->link)) {
//If not selected DB
die('Could not select specified database: '.mysql_error());
}
}
function request($sql) {
//Function request
$this->query = $sql;
if(is_resource($this->link)) {
if(is_resource($this->result)) {
mysql_free_result($this->result);
}
$this->result = mysql_query($this->query) or die('Could not execute SQL query: '.mysql_error());
return true;
} else {
$this->connect();
}
}
function numrows() {
//Function numrows
if(is_resource($this->result)) {
$num = mysql_num_rows($this->result);
return $num;
} else {
$this->request($this->query);
$this->numrows();
}
}
function fetch_assoc() {
//Function fetch_assoc
if(is_resource($this->result)) {
$row = mysql_fetch_assoc($this->result);
if(is_array($row)) {
return $row;
} else {
return false;
}
} else {
$this->request($this->query);
$this->fetch_assoc();
}
}
function fetch_object() {
//Function fetch_object
if(is_resource($this->result)) {
$row = mysql_fetch_object($this->result);
return $row;
} else {
$this->request($this->query);
$this->fetch_object();
}
}
function close() {
//Function close
if(is_resource($this->link)) {
return mysql_close($this->link);
}
}
}
?>
PHP-Code:
<?php
define('prefix', 'wr_');
require_once '../includes/class/mysql.php';
$db = new db;
$db->request("SELECT * FROM ".prefix."users;");
if($db->numrows() > 0) {
while($ni = $db->fetch_object()) {
echo $ni->id . '<br>';
}
while($in = $db->fetch_assoc()) {
echo $in['name'] . '<br>';
}
} else {
echo 'Nix zum ausgeben da!';
}
?>
PHP-Code:
if($db->numrows() > 0) {
PHP-Code:
function numrows() {
//Function numrows
if(is_resource($this->result)) {
$num = mysql_num_rows($this->result);
return $num;
} else {
$this->request($this->query);
$this->numrows();
}
}
//EDIT:
Also es wird immer 0 ausgegeben, auch wenn in der DB einträge vorhanden sind.
Kommentar