bin gerade dabei, mir ne SQL Klasse zu schreiben. Sodala, funktioniert auch alles wunderbar. Beim SELECT Query wird allerdings immer der erste Eintrag ignoriert. Könnt ihr mir vielleicht sagen warum?
PHP-Code:
<?php
error_reporting(E_ALL);
class createSQL
{
private $host = "";
private $user = "";
private $pass = "";
private $data = "";
private $pref = "";
private $handle = FALSE;
private $lastquery = "";
// automaticly connect to database
public function __construct($_host, $_user, $_pass, $_data, $_pref)
{
$this->host = $_host;
$this->user = $_user;
$this->pass = $_pass;
$this->data = $_data;
$this->pref = $_pref;
self::connectServer();
self::selectDatabase();
}
// function to establish server connection
private function connectServer()
{
$this->handle = mysql_connect($this->host, $this->user, $this->pass)
OR die("Could not Connect to Database".mysql_error());
}
// function to select database
private function selectDatabase()
{
mysql_select_db($this->data, $this->handle)
OR die("Could not select Database".mysql_error());
}
// send mysql query
public function query($_query)
{
$this->lastquery = mysql_query($_query)
OR die("Could not create query".mysql_error());
}
// fetch result from last query
public function fetch()
{
mysql_fetch_array($this->lastquery)
OR die("Could not fetch last query".mysql_error);
$count = 0;
while($record = mysql_fetch_array($this->lastquery, MYSQL_ASSOC))
{
$count ++;
$result[$count] = $record;
}
return $result;
}
}
?>
PHP-Code:
<?php
require_once("class.sql.inc");
$SQLmemberdata = new createSQL("localhost","user","pass","db","");
$SQLmemberdata->query("SELECT * FROM `test`");
$_data = $SQLmemberdata->fetch();
echo "<pre>";
print_r($_data);
echo "</pre>";
?>
Andain
Einen Kommentar schreiben: