Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9241665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:24:42+00:00 2026-06-18T08:24:42+00:00

By reading on stackoverflow I solved almost all of my problems. But now I’ve

  • 0

By reading on stackoverflow I solved almost all of my problems. But now I’ve got a very “special” one I can’t explain. Hours of googling and researching, but there is no solution.

class:

class Beitrag_Loeschen {
private $debug;
private $do_debug;

function __construct() {
    $this->do_debug = TRUE;
}

function __destruct() {
    if ($this->do_debug == TRUE) {
        mysql_query("INSERT INTO `seite_log` (`id`, `timestamp`, `benutzer_ip`, `benutzer_id`, `datei`, `referrer`, `fehler`, `kommentar`) VALUES (NULL, UNIX_TIMESTAMP(), '', 1, '', '', '', '')");
    }
}

private function _deleteDir($dir) { 
    // more code
}

// SQL-Query
private function _queryDelete($tabelle, $spalte, $id) {
    $query = "DELETE FROM `".sql($tabelle)."` WHERE `".sql($spalte)."`='".sql($id)."';";
    mysql_query($query);
    $this->debug .= $query."<br/>";
}
private function _queryDeleteKat($tabelle, $kat, $kat_id) {
    $query = "DELETE FROM `".sql($tabelle)."` WHERE `kat`='".sql($kat)."' AND `kat_id`='".sql($kat_id)."'";
    mysql_query($query);
    $this->debug .= $query."<br/>";
}
private function _seiteSuchbegriffe($ergebnis_typ, $ergebnis_id) {
    $query = "DELETE FROM `seite_suchbegriffe` WHERE `ergebnis_id`='".sql($ergebnis_id)."' AND `ergebnis_typ`='".sql($ergebnis_typ)."'";
    mysql_query($query);
    $this->debug .= $query."<br/>";
}

// Kommentare
function bewertungKommentar($id) {
    $this->_queryDelete('bewertungen_kommentare',   'id',               $id); // bewertungen_kommentare
}
function fotoKommentar($id) {
    $this->_queryDelete('fotos_kommentare',         'id',               $id); // fotos_kommentare
}
function rezeptKommentar($id) {
    $this->_queryDelete('rezepte_kommentare',           'id',               $id); // rezepte_kommentare
}

// Bewertung
function bewertung($id) {
    $this->_queryDelete('bewertungen_burger',           'id',               $id); // bewertungen_burger
    $this->_queryDelete('bewertungen_kommentare',   'bewertung_id',     $id); // bewertungen_kommentare
    // more code
}

// Foto
function foto($id) {
    $this->_queryDelete('fotos_kommentare',             'foto_id',          $id); // fotos_kommentare
    // more code
}

// Burger
function burger($id) {
    $this->_queryDelete('burger',                       'id',               $id); // burger
    $this->_queryDeleteKat('benutzer_aktionen',         'favorit_burger', $id); // benutzer_aktionen
    // more code
}

// Lokalität
function lokalitaet($id) {
    $this->_queryDeleteKat('seite_korrekturen',         'lokalitaet',       $id); // seite_korrekturen
    $this->_queryDeleteKat('seite_hits',                'lokalitaeten',     $id); // seite_hits
    // more code
}
}

My concept: If you want to, e. g., delete a location you have to delete rows from several tables. For this purpose I wrote this little PHP class. While deleting the stuff there are performed many mysql queries in many tables and therefore I needed a way to debug.

The debug information are stored in $debug.

$this->debug .= $query."<br/>";

Finally, $debug should stored in the database (after calling the class there is a “header(“Location: …”)”, so I could not perform an “echo”). The DB query for this is called in the destructor (INFO: the query is only a dummy. So I could obviate that there is no problem with the query-syntax):

function __destruct() {
    if ($this->do_debug == TRUE) {
        mysql_query("INSERT INTO `seite_log` (`id`, `timestamp`, `benutzer_ip`, `benutzer_id`, `datei`, `referrer`, `fehler`, `kommentar`) VALUES (NULL, UNIX_TIMESTAMP(), '', 1, '', '', '', '')");
    }
}

The class is called by this:

$del = new Beitrag_Loeschen();
$del->bewertungKommentar($id);
//header("Location: ".$referer);

THE PROBLEM:
There seems to be no db connection within the destructor, because I got this error all the time:

Warning: mysql_query() [function.mysql-query]: Access denied for user ''@'localhost' (using password: NO) in /[...]/classes/beitrag_loeschen.inc.php on line 12
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /[...]/classes/beitrag_loeschen.inc.php on line 12

(line 12 is the mysql_query in the destructor)

What am I doing wrong? The other mysql_querys in the class are working perfectly.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:24:43+00:00Added an answer on June 18, 2026 at 8:24 am

    Unless you are explicitly calling the __destruct() function or handling your references to the object very closely and know exactly when it gets unset there is no guarantee when __destruct() will be called by the language. By the time it is called the language has already released the resource for your connection to the database. mysql_query() attempts to create a new connection, using the default server parameters and fails to do so because there is no blank user.

    To reliably log your information you need to explicitly make the call to run the query. If you rely on __destruct() for this you will likely always encounter some problem similar to the one you’re having.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been reading StackOverflow too much and started doubting all the code I've ever
After reading all sorts of Stackoverflow postings and various documentation including some on http://code.google.com/p/google-api-java-client/
I was reading How can I get query string values in JavaScript? on Stackoverflow
I've seen a lot of questions on that on StackOverflow, but reading the answers
I have been reading StackOverflow for a while and now I have a question
Hey, I've been reading StackOverflow.com for a long time but decided to sign up
I've been reading StackOverflow for quite a while now and I'm only now building
Guys, I opened this question (I hope could help some others) but reading stackoverflow
After reading quite a couple of questions in stackoverflow, I still can't find an
I have been reading stack overflow for a solution but can't find it. (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.