stfc_boy
10-14-2009, 02:03 PM
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.
<?
// 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:
$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
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.
<?
// 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:
$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