Von den unten im Code stehenden 2 Beispielen funktioniert das obere nicht. Es gibt nichts zurück. Wieso??? Das Query wird korrekt zusammengesetzt, denn $debug = 1 gib mir das Query auch aus. Wenn ich das Query in phpmyadmin ausführe funktioniert es auch und bringt mir eine Zeile zurück. Irgendwelche Ideen?
PHP-Code:
<?
// mysql class
class mysql
{
protected $db_host = 'localhost';
protected $database = '';
protected $db_user = '';
protected $db_pass = '';
protected $db_port = '';
protected $db_prefix = 'fl_';
protected $fields = '*';
public $debug = 0;
// constructor
public function __construct()
{
$this->connection = @mysql_pconnect($this->host.':'.$this->db_port, $this->db_user, $this->db_pass)
or die("{connect} Database Error: ".mysql_errno()." : ".mysql_error());
$this->select_database = @ mysql_select_db($this->database, $this->connection)
or die("{select_db} Database Error: ".mysql_errno()." : ".mysql_error());
}
// destructor
public function __destruct()
{
$this->close();
}
// close a connection
public function close()
{
//$this->connection = mysql_close();
}
// process a query
public function query($querystring)
{
// count the connections
$this->db_count = !isset($this->db_count) ? 1 : $this->db_count + 1;
// connect to the database
//if ($this->connection == false) $this->connect();
//if ($this->connection == false) return;
// return results or errorhandling
$this->result = mysql_query($querystring, $this->connection)
or die("Database Error : ".mysql_errno()." : ".mysql_error().$querystring);
// if debug is set, return the query
if($this->debug == 1)
{
echo $querystring;
}
$this->result;
// give the memory free
//mysql_free_result($this->result);
}
// fetch results as objects
public function fetch_object()
{
if (is_resource($this->result))
{
$row = mysql_fetch_object($this->result);
if(is_object($row))
{
return $row;
}
else
{
return FALSE;
}
}
}
// fetch results as array
public function fetch_assoc()
{
if (is_resource($this->result))
{
$row = mysql_fetch_assoc($this->result);
if(is_array($row))
{
return $row;
}
else
{
return FALSE;
}
}
}
public function set_table($table)
{
$this->table = $table;
}
public function set_where($string)
{
$this->where = ' WHERE '.$string;
}
public function set_fields($string)
{
$this->fields = $string;
}
public function select()
{
$this->query('SELECT '.$this->fields.' FROM '.$this->table.$this->where);
}
}
$sql = new mysql;
$sql->debug = 1;
$sql->set_fields('ID_MEMBER, name');
$sql->set_table('fl_members');
$sql->set_where("ID_MEMBER = '1'");
$sql->select();
while ($row = $sql->fetch_object());
{
$tmp = $tmp.$row->name.'<br />';
}
echo $tmp;
echo '<br />###########################################################################<br />';
$sql2 = new mysql;
$sql2->query('SELECT * FROM fl_members');
while ($row = $sql2->fetch_object())
{
$tmp = $tmp.$row->name.'<br />';
}
echo $tmp;
?>
Kommentar