A fatal error on a class not found

HI all I was testing my script (SpamFilter.php) yesteday everything went fine I was running in on my rackspace server and its worked and sent me an email.
Today I was runing it again and all of a sudden I get the message


PHP Fatal error:  Class 'MySQLConnection' not found in BaseModel.php on line 76

even If i comment the require for the base model it will still shoe this error which is weird How can he show an error on basemodel when SpamFilter doesnt even load it??

I spend hours trying to understand whats going on here and how come its work perfectly fine yesterday
please help
 
SpamFilter.php

<?php
require_once('BaseModel.php');
require_once('IModel.php');
require_once('ServiceRequest.php');



Class Keywords extends BaseModel {
	
	protected $word;
	protected $spamOcc;
	protected $hamOcc;
	protected $_isUpdate;
	
	public function Keywords ($word = null,$spamOcc = null, $hamOcc = null, $isUpdate = null){
		
		if(is_null($word) && is_null($spamOcc) && is_null($hamOcc)  && is_null($isUpdate)){
			parent::__construct();
		}else {
			$this->word = $word;
			$this->spamOcc = $spamOcc;
			$this->hamOcc = $hamOcc;
			$this->_isUpdate = $isUpdate;
			
		}			
	}
	
	 public function get_spamOcc()
    {
        return $this->spamOcc;
    }
	 public function get_hamOcc()
    {
        return $this->hamOcc;
    }
	
	public function get_word()
    {
        return $this->word;
    }
	
	public function set_word($word)
	{
	  $this->word = $word;
	}
	
	public function set_spamOcc($spamOcc)
	{
	  $this->spamOcc = $spamOcc;
	}
	
	public function set_hamOcc($hamOcc)
	{
	  $this->hamOcc = $hamOcc;
	}
	
/**
     * get all the records from the keywords table.
     *
     * @param none
     *
     * @access public static
     * @return array of keywords objects (The content of Keywords table)
     */	
	public static function getAll()
    {
        $query = <<<EOB
SELECT
    *
FROM
    Keywords
EOB;

        $sql = BaseModel::getSqlObject();

        $results = $sql->Query($query);
        $output = array();

        if ($results && $results->num_rows > 0) {
            while (($row = $results->fetch_assoc())) {
                if ($row) {
                    $newRequest = new Keywords();

                    $newRequest->set_word($row['word']);
                    $newRequest->set_spamOcc($row['spamOcc']);
                    $newRequest->set_hamOcc($row['hamOcc']);
                    $newRequest->set_isUpdate(true);

                    $output[] = $newRequest;
                }
            }
        }

        $sql->FreeAll();

        return $output;
    }
	
	public static function getbyWord($word)
    {
	     $safeWord = $sql->Escape($word);
        $query = <<<EOB
SELECT
    *
FROM
    Keywords
WHERE
	word ='{$safeWord}'
EOB;

        $sql = BaseModel::getSqlObject();

        $results = $sql->Query($query);
        

        if ($results && $results->num_rows > 0) {
            while (($row = $results->fetch_assoc())) {
                if ($row) {
                    $newRequest = new Keywords();

                    $newRequest->set_word($row['word']);
                    $newRequest->set_spamOcc($row['spamOcc']);
                    $newRequest->set_hamOcc($row['hamOcc']);
                    $newRequest->set_isUpdate(true);

                  //  $output = $newRequest;
                }
            }
        }

        $sql->FreeAll();

        return $newRequest;
    }
/**
     * Save the object properties into the db
     *
     * @param none
     *
     * @access public
     * @return 
     */		
	public function save()
    {
        $result = false;
        if ($this->_isUpdate) {
            $result = $this->_saveUpdate();
        } else {
            $result = $this->_saveNew();
        }

        return $result;
    }


    protected function _saveNew()
    {
        $sql = BaseModel::getSqlObject();

        $query = <<<EOB
INSERT INTO Keywords(
    word,
    spamOcc,
    hamOcc
	)
VALUES(
    '{$sql->Escape($this->get_word())}',
    '{$sql->Escape($this->get_spamOcc())}',
    '{$sql->Escape($this->get_hamOcc())}'
	)
EOB;

        $results = $sql->Query($query);

        $sql->FreeAll();

        return($results && $results->num_rows > 0);
    }
	
	
	 
	 

/**
     * Save the object properties into the db neew to calcalte it beofre
     *
     * @param none
     *
     * @access public
     * @return 
     */		
    protected function _saveUpdate()
    {
        $sql = BaseModel::getSqlObject();

        $query = "UPDATE Keywords " . 
                "SET " . 
                "spamOcc='" . $sql->Escape($this->get_spamOcc()) . "'," .
                "hamOcc='" . $sql->Escape($this->get_hamOcc()) . "'," .
                "WHERE word='" . $sql->Escape($this->get_id()) . "'";

        $results = $sql->Query($query);

        $sql->FreeAll();

        return($results && $results->num_rows > 0);
    }
	 

	public static function saveByword($word, $countSpamOcc,$countHamOcc){
	
	
		$newKeyword = new Keywords;
		$newKeyword->set_word($row['word']);
        $newKeyword->set_spamOcc($row['spamOcc']);
        $newKeyword->set_hamOcc($row['hamOcc']);
		
		$existKeywords = Keywords :: getbyWord($word);
	//check if the word doesnt  exist
		if (empty($existKeywords)){
			$newKeyword->set_word($word);
			$newKeyword->set_spamOcc($countSpamOcc);
			$newKeyword->set_hamOcc($countHamOcc);
			$newKeyword->set_isUpdate(false
			
			
			);
			//$newKeyword->_saveNew();
		}
		else {
		    $newSpamOcc = $existKeywords->get_spamOcc() + $countSpamOcc;
			$newHamOcc = $existKeywords->get_hamOcc() + $countHamOcc;
			
			$newKeyword->set_word($word);
		    $newKeyword->set_spamOcc($newSpamOcc);
			$newKeyword->set_hamOcc($newHamOcc);
			$newKeyword->set_isUpdate(true);
			//$newKeyword->saveUpdate();	
	    }
		
	$newKeyword->save();	
		
	}
}//class
	
	
//}

Class SpamFilter{ 
		
	const  SPAM_THRESHOLD = 20;////Anything that gets a score over this number is spam.
	
	const  KEYWORDS_THRESHOLD = 0.95; //The minimum probability to detect spam
	private $keywords;
	private $totalCheckedSpam;            //The total number of emails checked for spam
	private $totalCheckedHam;              //The total number of emails checked for ham
	
	
	/**
     * constractor -upload the info from Keywords table to keywors
     */
	public function SpamFilter(){
	
		 $this->keywords = Keywords::getAll();
		//$this->totalCheckedSpam = ServiceRequest::getTotalKeywords(1);
		//$this->totalCheckedHam = ServiceRequest::getTotalKeywords(0);		  
	}
	/**
     * check if a text is consider  as spam base on the basienfilterspam.and the defined thershold 
     *
     * @param object $text
     * @return true id the email is spam, false if not.
     */
	public function checkKeywordSpam($text){
			
		$text = $this->extractContent($text);
		//returns an array containing all the words found inside the string
		$words = str_word_count($text,1);
		$mulP = 1;
		$mulCompP = 1;
		foreach ($words as $word){			
			
		 $p = $this->calcWordProbability($word); 
		 if ($p !=0) {
			$mulP = $mulP*$p;
			$mulCompP = $mulCompP*(1-$p);		
			}
		}
		$finalP = $mulP/($mulP+$mulCompP);
		
		$return = ($finalP >= self::KEYWORDS_THRESHOLD )?  true :  false ;
		
		return $return;
	}
	
	
	/**
     * update the texts word in Keywords table
     *
     * @param object $text . $isspam 1/0
     * @return true id the email is spam, false if not.
     */
	public function updateKeywords($isSpam,$text)
	{
		$results = $this->countWords($text);
		foreach($results as $k=>$v){
			if ($isSpam){
			   $countSpamOcc = $v;
			   $countHamOcc = 0;
			}
			else{
				$countSpamOcc = 0;
				$countHamOcc = $v;
			}
			
			Keywords::saveByword($k,$countSpamOcc,$countHamOcc);			
		}	
	}
	/**
     * check if a string has an url in it
     *
     * @param str any giving string
     * @return true if the text has an url and false if not .
     */
	public	function checkIfUrl($str){
		$match = preg_match('/http:\/\/(.*)/s', $str);
		return ( $match == 0 )? false : true; 
	}
	
	
	/**
     * NotUsing for now
     *
     * 
     * 
     */
	private function countWords ($text){
		$results = array();
		$words = str_word_count($text,1);  //returns an array containing all the words found inside the string
		$words = array_unique($words); //no really need for that  but just incase for future changes
		foreach($words as $word){
			preg_match_all("/\b$word\b/", $text, $matches,PREG_PATTERN_ORDER);
			$results[$word] = count($matches[0]);
		}
		arsort($results);          //in Desc order by max occurrences
	
		return $results;	 
	}
	
	
	private function extractContent($text){
	$html=strip_tags($text);
	$commonWords = array('is','that','them','and','he','the','-','of','to','for','were','was','--','in','at','as','a','an','on','by','or','it',
	'us','be','her','me','we','will','so','she','i','this','has','have','off','been','nbsp','s','\'s','you','my','don\'t','can','your','won\'t','are','if','what');
	
	$text = strtolower($html);//text
	$cleanText = preg_replace('/\b('.implode('|',$commonWords).')\b/','',$text);
	$text = preg_replace('/\b('.implode('|',$commonWords).')\b/','',$text);
	return  $text;//$html
	}
	
	
	/**
     * calculate the word probabilty to be spam 
     * based on The spamicity of a word http://en.wikipedia.org/wiki/Bayesian_spam_filtering
     * @param string $word
     * @return double a probabilty of the word to be spam or 0 as an indication to ignore the word.
     */
	
	private function calcWordProbability($word){
	  
		$wordInfo = $this->findWord($word);
		if (!is_null($wordInfo)){ 
	  
			$spamOcc = $wordInfo->get_spamOcc();
			$hamOcc =  $wordInfo->get_hamOcc();
		
			$pWordToBeSpam = $spamOcc/$this->totalCheckedSpam;
			$pWordTOBeHam =  $hamOcc/$this->totalCheckedHam;
			$s=3;
			$n = $spamOcc + $hamOcc;
	  
			$tempP = $pWordToBeSpam/($pWordToBeSpam+$pWordTOBeHam);  //The spamicity of a word
			$finalP =(($s*0.5) + ($n*$tempP))/($s+$n);      //Dealing with rare words adjusment 
			return $finalP;
		 
		}	
	
		else return 0;	
	}	
	/**
     * find a specific word in $keywords (a property of the class).
     * 
     * @param string $word
     * @return keywors object or null.
     */
	private function findWord($word)
	{
		foreach($this->keywords as $keyword){
		  if (strcmp($keyword->get_word(),$word)== 0){
				return $keyword;
		  } 		  
		}
		$keyword = null;
		return $keyword;
	}
		
 } //class
  
  //check to see if its a spam
	    //has a link in the adress or comments
		$spamFilter = new Spamfilter();
		$checkUrl = $spamFilter->checkIfUrl("We found your weblisting on one of the back pages of Google.  Wouldn’t you rather be up front?  Our experts in Search Engine Optimization can help you become more visible and more productive.  A quick email will get you details.");
		
		if ($checkUrl == FALSE){$spamFilter->checkIfUrl("We found your weblisting on one of the back pages of Google.  Wouldn’t you rather be up front?  Our experts in Search Engine Optimization can help you become more visible and more productive.  A quick email will get you details.");}
		
		//check if the email is spam according to keywords
		if ($checkUrl == FALSE){
		
			$checkKeywords = $spamFilter->checkKeywordSpam("We found your weblisting on one of the back pages of Google.  Wouldn’t you rather be up front?  Our experts in Search Engine Optimization can help you become more visible and more productive.  A quick email will get you details");
			$isSpam = ($checkKeywords == True )? 1 : 0;
			//update the db in the new mail information (incase its not an url				
		}
		
		//$emailSpam = checkEmailB($_POST['email']);
		
		
		$emailSpam  = False;
		 if ($emailSpam == FALSE  && $checkKeywords == FALSE && $checkUrl == false) {
          //@sendEmail($toAddress, $subject, $message, $_POST['email'], $domain, $ip,0);
		     $mail = mail("email.com","test","test");
		}
		else{
			$subjectSpam = ($checkUrl == TRUE) ? "goteq-spam-url" : "goteq-spam";	
			$subjectSpam =( $isSpam == 1)? "goteq-apam-keywords" : "goteq-spam";
			//@sendEmail('nurit@goteq.com', $subjectSpam, $message, $_POST['email'], $domain, $ip,1);
			$mail = mail('email.com',$subjectSpam,"test");
		}

?>

Open in new window



<?php

 */
class BaseModel
{
    /**
     * The SQL object to use.
     *
     * @var MySQLConnection|null
     * @access protected
     */
    protected static $_sql = null;

    /**
     * Whether this is an extant record.
     *
     * @var boolean
     * @access protected
     */
    protected $_isUpdate = false;


    /**
     * Construct the object.
     *
     * @access public
     */
    public function __construct()
    {
    }


    /**
     * Get whether this entity is an extant record.
     *
     * @access public
     * @return boolean
     */
    public function get_isUpdate()
    {
        return $this->_isUpdate;
    }


    /**
     * Set whether this entity is an extant record.
     *
     * @param boolean $_isUpdate
     *
     * @access public
     * @return boolean
     */
    public function set_isUpdate($_isUpdate)
    {
        $this->_isUpdate = $_isUpdate;
    }


    /**
     * Get the SQL object.
     *
     * @static
     * @access public
     * @return MySQLConnection|null
     */
    public static function getSqlObject()
    {
        $sql = new MySQLConnection();

        if (! $sql->Connect())
            die(ShowError("Server Connection Error"));

        return($sql);
    }


}

Open in new window

Nura111Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kevthedudeCommented:
Commenting out the require basemodel likely didn't do anything because it's included in another file. However, if it's not included at all you will get another error because your class is extending the basemodel. Your main error is that your code is calling the class "MySQLConnection" but it's not included anywhere. Find the file that contains that class and add it to the require_once list. Since it's used in BaseModel.php you should have the require at the top of that file.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
When things are working well "yesterday" but are broken today, it usually means that the programming has changed, or the server configuration has changed.  If you are using version control software like GIT or SubVersion, you can just roll back to yesterday's version of the code.  Sometimes you may find that your hosting company had to replace a server or a disk drive and your code got replaced with an older version in the process.  In those cases you can use your version control software to make a new build.
0
Nura111Author Commented:
kevthedude:  to require a file in the folder above

(Spam filter at folder and the file to incluse is in public/folder)


Ray_Paseur:: I have no Idea how to do it Can you explain?
0
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Ray PaseurCommented:
Who is the hosting company?  Have you asked them about backup / restore operations?
0
Nura111Author Commented:
Thanks, I used the require one and its worked
0
Nura111Author Commented:
Does anyone can still answer to require a file in the folder above

(Spam filter at folder and the file to incluse is in public/folder)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.