I am currently coding backend coding to a news managment system and I'm working on a function to delete news articles. The function works great but I'm running into an unusual problem where the Pear:😃B function free(); that frees the SQL query cache is causing a fatal error - non-object error. Here is the exact error message:
Fatal error: Call to a member function on a non-object in /home/nova-des/public_html/includes/news.inc.php on line 79
Here is the code:
function nova_newsDelete ( $newsID )
{
//--- Require config.inc.php and Pear::DB class file.
require_once ( 'config.inc.php' );
require_once ( 'DB.php' );
//--- Open a connection to the database. If it fails print error message.
$novadb = DB::connect ( $dsn, TRUE );
if ( DB::isError ( $novadb ) )
{
die ( $novadb->getMessage() );
}
//--- Check to make sure $newsID is a numerical value first before generating the SQL query.
if ( is_numeric ( $newsID ) )
{
$novasql = "DELETE FROM nova_news WHERE newsID = '$newsID'";
$novares = $novadb->query ( $novasql );
if ( DB::isError ( $novares ) )
{
die ( $novares->getMessage() );
}
//--- Count the number of rows left after the deletion of an article and resets the incrementation for article number assignments.
$novasql = "SELECT * FROM nova_news";
$novares = $novadb->query ( $novasql );
if ( DB::isError ( $novares ) )
{
die ( $novares->getMessage() );
}
$nova_newsCount = $novares->numRows();
//--- Reset the incrementation based on last query.
$novasql = "ALTER TABLE nova_news AUTO_INCREMENT = $nova_newsCount";
$novares = $novadb->query ( $novasql );
if ( DB::isError ( $novares ) )
{
die ( $novares->getMessage() );
}
//--- Print success message when deletion process has completed.
print ( ''."\n\t\t".'<p xml:lang="en" class="text-left">The requested news article has been successfully deleted.</p>'."\n" );
}
else
{
print ( ''."\n\t\t".'<p xml:lang="en" class="text-left">Your request to delete an article has failed because you did not supply a numerical integer for newsID. Please try again.</p>'."\n" );
}
//--- Clear the SQL query cache and disconnect from the database.
$novares->free();
$novadb->disconnect();
}
Line 79 is $novares->free();
Now what I cannot understand is in other functions that use the same exact line give no fatal error issue. The only thing I can conclude is the if ( is_numeric ( $newsID ) ) statement is somehow causing a problem but I need a second opinion on this. Any suggestions are welcome.