View Full Version : No connection to my database?

10-14-2009, 03:03 PM
Help with a function in a class


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.


// 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);

//Create a Function to grab the data out of MYSQL and hold each record in write_job_details

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);


} //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:

$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)?


10-14-2009, 03:10 PM
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?