Hi,
i coded a Mysql-Class, there are no compiling-errors when i run it.
But the problem is that it doesn�t do what i want it to do.
I added the sourcecode below and would be happy for any sugestions
how to make it better.
Cu Johannes Hiemer
Code:
<?
class get_db {
var $database = "forum";
var $islinked = 0;
var $iserror = 0;
var $reporterror = array();
var $islinux = 0;
var $server = "localhost";
var $user = "root";
var $password = "";
function connect() {
if ($islinux == 1) {
$use_pconnect = 1;
global $use_pconnect;
}
else {
$use_pconnet = 0;
global $use_pconnect;
}
if(0 == $this->islinked) {
if($password == "") {
if($use_pconnect == 0) {
$this->link_id = mysql_pconnect($this->server,
$this->user);
}
else {
$this->link_id = mysql_connect($this->server, $this->user,
$this->password);
}
}
else {
if($use_pconnect == 1) {
$this->link_id = mysql_pconnect($this->server,
$this->user);
}
else {
$this->link_id = mysql_connect($this->server,
$this->user, $this->password);
}
}
}
if(!$this->link_id) {
$this->stopm("Couldn�t connect to: ".$this->server.
" with ".$this->user."".mysql_error."reason");
}
if(!$this->database == "") {
$this->db_query = mysql_db_query($this->database,
$this->link_id);
$this->stopm("Couldn�t connect to".$this->database);
}
}
function error() {
$this->error = mysql_error();
return $this->error;
}
function errno() {
$this->errno = mysql_errno();
return $this->errno;
}
function reporterrno() {
$this->errno = mysql_errno();
$this->file = "db_logs.txt";
if(file_exists($this->file)) {
$this->openlogfile = fopen($this->file, "a+");
if(feof($this->openlogfile)) {
fputs($this->openlogfile, date("d.M.Y h:m:s",
time())."<br>".$REMOTE_ADDR."<br>\n".$this->errno);
fclose($this->openlogfile);
}
}
else {
$this->openlogfile = fopen($this->file,"a+");
if(feof($this->openlogfile)) {
fputs($this->openlogfile, date("d.M.Y h:m:s",
time()).",".$REMOTE_ADDR."<br>n");
fclose($this->openlogfile);
}
@mail("[EMAIL PROTECTED]", 'Mysql_error: ".$this->errno."',
date("d.M.Y h:m:s", time()).",".$REMOTE_ADDR."<br>\n".$this->errno."");
}
}
function db_select($database) {
$this->database = $database;
$this->db_query = mysql_select_db($this->database, $this->link_id);
$this->stopm("Couldn�t connect
to".$this-database."reason".$this->error);
}
function db_query($string_query) {
$this->query = mysql_query($string_query, $this->link_id);
if(!$this->query) {
$this->stopm("Invalid Mysql_query: ".$string_query);
}
return $this->query;
}
function fetch_array($string_query) {
if (isset($query_string)) {
if(!empty($string_query)) {
$this->stopm("Query was emtpy or wrong".$this->error);
}
$this->fetch_data = mysql_fetch_array($this->query, $this->link_id);
if(!$this->fetch_data) {
$this->stopm("Query was emtpy or wrong".$this->error);
}
else {
return $this->fetch_data;
}
}
}
function stopm($msg) {
$this->error=mysql_error();
$this->errno=mysql_errno();
if ($this->reporterror == 1) {
$message="Database error in $this->appname: $msg\n";
$message.="mysql error: $this->error\n";
$message.="mysql error number: $this->errno\n";
$message.="Date: ".date("l dS of F Y h:i:s A")."\n";
$message.="Script: ".getenv("REQUEST_URI")."\n";
$message.="Referer: ".getenv("HTTP_REFERER")."\n";
@mail("[EMAIL PROTECTED]", 'Mysql_error: ".$this->errno."',
date("d.M.Y h:m:s", time()).",".$REMOTE_ADDR."<br>\n".$this->errno."");
echo "\n<!-- $message -->\n";
echo "</td></tr></table>\n<p>Es sind Probleme mit der Datenbank
aufgetreten.\n";
echo "Versuchen sie es erneut in dem sie den Refresh Button des
Browser nutzen.</p>";
echo "Es wurde eine Email an unseren Techniker gesendet<a
href=\"mailto:$technicalemail\">Techniker</a>, der mit diesem Link
kontaktiert werden kann, sofern der Fehler erneut auftritt.</p>";
echo "<p>Wir bitten vielmals um Entschuldigung.</p>";
die("");
}
}
}
$test = new get_db();
$test -> connect();
$test -> db_query("SELECT * FROM topics");
$test -> fetch_array("SELECT * FROM topics");
echo "$test";
?>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]