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:
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())."".$REMOTE_ADDR."\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."n");
fclose($this->openlogfile);
}
@mail("[EMAIL PROTECTED]", 'Mysql_error: ".$this->errno."',
date("d.M.Y h:m:s", time()).",".$REMOTE_ADDR."\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."\n".$this->errno."");
echo "\n\n";
echo "\nEs sind Probleme mit der Datenbank
aufgetreten.\n";
echo "Versuchen sie es erneut in dem sie den Refresh Button des
Browser nutzen.";
echo "Es wurde eine Email an unseren Techniker gesendetmailto:$technicalemail\";>Techniker, der mit diesem Link
kontaktiert werden kann, sofern der Fehler erneut auftritt.";
echo "Wir bitten vielmals um Entschuldigung.";
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]