我试图让这段代码返回一个包含查询结果的数组。但它返回的数组总是空的,但我没有收到任何错误,所以我完全失去了它。
function selectAll()
{
print $sql = "SELECT id FROM user;";
$result = $this->database->query($sql);
$result = $this->database->result;
print $result;
while ($array_fila = mysqli_fetch_array($result)) {
$this->setId($array_fila["id"]);
$this->select($this->getid());
$array_users[] = clone $this;
}
return $array_users;
}
我使用的班级数据库是以下
<?php
class Database
{ // Class : begin
var $host; //Hostname, Server
var $password; //Passwort mysql
var $user; //User mysql
var $database; //Datenbankname mysql
var $link;
var $query;
var $result;
var $rows;
function Database()
{ // Method : begin
//Konstruktor
// ********** DIESE WERTE ANPASSEN **************
// ********** ADJUST THESE VALUES HERE **********
$this->host = "127.0.0.1"; // <<---------
$this->password = "eldiego123"; // <<---------
$this->user = "root"; // <<---------
$this->database = "wargame"; // <<---------
$this->rows = 0;
// **********************************************
// **********************************************
} // Method : end
function OpenLink()
{ // Method : begin
$this->link = @mysql_connect($this->host,$this->user,$this->password) or die (print "Class Database: Error while connecting to DB (link)");
} // Method : end
function SelectDB()
{ // Method : begin
@mysql_select_db($this->database,$this->link) or die (print "Class Database: Error while selecting DB");
} // Method : end
function CloseDB()
{ // Method : begin
mysql_close($this->link);
} // Method : end
function Query($query)
{ // Method : begin
$this->OpenLink();
$this->SelectDB();
$this->query = $query;
$this->result = mysqli_query($query,$this->link) or die (print "Class Database: Error while executing Query");
// $rows=mysql_affected_rows();
if(ereg("SELECT",$query))
{
$this->rows = mysql_num_rows($this->result);
}
$this->CloseDB();
} // Method : end
} // Class : end
?>
提前致谢!