Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Posts
    310
    Thanks
    86
    Thanked 3 Times in 3 Posts

    No connection to my database?

    Help with a function in a class

    Hi,

    I'm having trouble with a function within a class called Getjobs()

    Basically In the function IndesignFile I create a text file on the fly and add a couple of lines to it and save it on my server - this works with no problems.


    PHP Code:
    <?

    // Make a MySQL Connection
    mysql_connect("localhost""***********""**********") or die(mysql_error());
    mysql_select_db("**************") or die(mysql_error());


    //Set the class IndesignFile

    class IndesignFile
    {    
        function 
    IndesignFile()
        {
            
            
    $date_time_stamp date("d-m-Y");
            
    $this->f_file_name "/home/inspirea/datafiles/file-".$date_time_stamp.".txt";
            
    $this->f_header_text "<v2.05><e0>\r";
            
    $this->f_header_text .= "<-- Opening Line text -->";
            
    $this->f_header_text .= "<-- Second Line text -->";
            
            
    $this->f_file_handle fopen($this->f_file_name'a');
            
    fwrite($this->f_file_handle$this->f_header_text);
            
    fclose($this->f_file_handle);
        }


    //Create a Function to grab the data out of MYSQL and hold each record in write_job_details 
    //THIS BIT FAILS AND SHOWS NO ERRORS?:
        
        
    function Getjobs()
        {
                  
    $result mysql_query("Select * from put_anything_here") or die(mysql_error());
                  
    $num_rows mysql_num_rows($result);

                  if(
    $num_rows 0)
            {
            
    /* Loop through the rest of the Jobs and */
              
    for($i=0$i <= $num_rows$i++)
                      {
                         
    $row_data mysql_fetch_array($result);
                         
    $this->write_job_details($row_data);
                 }
             }

           }

    //End of Class

    ?>

    My problem is when Getjobs() is called. Basically it won't connect to the database. In this line I could put anything:

    Code:
    $result = mysql_query("Select * from put_anything_here") or die(mysql_error());
    ie select monkey from dog ! or any text and it just ignores it, not even a mysql error which for some reason means its not connecting to the database. Anyone see why (PS my database connection details are fine)?

    Thanks

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,108
    Thanks
    2
    Thanked 326 Times in 318 Posts
    Where and how is the Getjobs() method of an instance of your class getting called?

    And are you developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that php would help you by displaying all the errors that it detects?
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •