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

  • SEARCH
  • Home
  • 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 560745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:22:34+00:00 2026-05-13T12:22:34+00:00

Below is a simple database class, well its part of a class, I stripped

  • 0

Below is a simple database class, well its part of a class, I stripped everything out except the parts related to my question.

Basicly it will allow me to build a file with all the queries that were ran on a page load with the time they took, the order they are in, the total count, and then also the actual SQL that was ran. It is very nice but I am having trouble. I cannot get it to write to the file, you can see below that I print to screen the value of $sss which is the value that should be written to file. In PHP I have error reporting set to show everything and I get no write errors or anything, it just doesn’t write to the file, possibly I may have the file on the wrong folder but I am not sure.

So what would be a good way to set a filepath to the log file and also to make it write? IF it cannot find the file now, should I see some sort of error?

<?PHP
class Database
{
    public $debug = true;
    public $query_count = 0;
    public $debug_file = "debug.sql";

    public function query($sql){
        //start timer stuff for debug logger
        list($usec, $sec) = explode(" ",microtime());
        $time_start  = ((float)$usec + (float)$sec);

        //run mysql query
        $result = mysql_query($sql);


        ///debug    
        list($usec, $sec) = explode(" ",microtime());
        $time_end  =  ((float)$usec + (float)$sec);
        $time = $time_end - $time_start;
        if($this->debug){
            $this->query_count ++;
            $f = fopen($this->debug_file, "a");
            $sss = "# ".$this->query_count."\n ".$time." sec \n\n".$sql."\n#-------------------------------------------------------------------------\n\n";

            // I print to screen just for test to see what should be wrriten to the file
            echo $sss;

            fputs($f, $sss, strlen($sss));
            fclose($f);
        }
        //end debug
    }
}
?>
  • 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-05-13T12:22:35+00:00Added an answer on May 13, 2026 at 12:22 pm

    First of all, I would use file_put_contents (http://php.net/manual/en/function.file-put-contents.php), it essentially bundles all those calls into one and can help avoid errors.

    If the echo statement is truly working, I would check for any errors being written to the php log file, and double check your settings in php.ini and make you are logging warnings.

    Also, check the return value of the fopen() call (it should not be false) … maybe its failing?

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

Sidebar

Related Questions

I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
I have a simple class as defined below: public class Person { int _id;
The code below consists of two classes : SmartForm (simple model class) SmartForms (plural
I have included all my code below (5 Classes) for a simple database of
Below is my very simple static class. Not sure what is wrong. I am
Below just a simple race between 2 button in 2 threads, and this will
Consider the simple example below of implementing a method in an Enum. One problem
For a simple plot below, is there a way to make matplotlib populate the
The code pasted below is a simple JSF program, with an idea of having
I am testing this simple code below and it works... $(document).ready( function() { $('.show-modal').click(

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.