Page 1 of 1

Fatal error: Class 'ezSQL_mysql' not found

Posted: Thu Nov 17, 2016 10:30 am
by shubhobd
After execute a file i found follwing error

Fatal error: Class 'ezSQL_mysql' not found in /home/voterank/public_html/advertisement/resources/simplead.class.db.php on line 64

please look at the file

Code: Select all

<?php
/**
 * This class is used to access a MySQL database
 *
 * @package SimpleFramework
 * @author  Robert Nduati
 */

class MySQLDatabase {
	private static $uniqueInstance;
/**
* The database connection
*
* @var resource
*/
	protected $connection;
	
/**
* An instance of the MySQLDbSettings class
*
* @var object
*/
	protected $settings;
	
	protected $show_errors = true;
	
/**
* When the class is instantiated a connection is made
*
* @return void
*/
	private function MySQLDatabase(){
		$this->Connect();
	}
	
	public static function GetInstance(){
		if(self::$uniqueInstance == null){
			self::$uniqueInstance = new MySQLDatabase();
		}
		return self::$uniqueInstance;
	}

/**
* Create the connection to the database
*
* @return void
*/
	public function Connect() {
        if ( DEVELOPMENT )
            $this->show_errors();

        if(USE_PDO){
            $this->ezSQL = new ezSQL_pdo('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD);

            $commands = array();
            $commands[] = 'SET SQL_MODE=ANSI_QUOTES';
            $commands[] = "SET NAMES '" . DB_CHARSET . "'";

            foreach ($commands as $value)
            {
                $this->ezSQL->dbh->exec($value);
            }
        }else{
            $this->ezSQL = new ezSQL_mysql(DB_USER,DB_PASSWORD,DB_NAME,DB_HOST);           
        }
	}

    function show_errors() {
        if(isset($this->ezSQL)){
            $this->ezSQL->show_errors();
        }
    }

    function hide_errors() {
        if(isset($this->ezSQL)){
            $this->ezSQL->hide_errors();
        }
    }
	
/**
* This closes a database connection
*
* @return void
*/
	public function Close() {
		return   null;
	}

/**
* This method creates a new record
* 
* @param $table: (Required) the table to use
* @param $values: (Required) an array of the values to save e.g. array('column'=>value)
*
* @return int
*/
	public function Create($table, $values) {
		$columns = $this->CommaSeparate(array_keys($values));
		$data = $this->CommaSeparateWithQuotes(array_values($values));

		$insertQuery = "INSERT INTO $table ( $columns ) VALUES ( $data )";

        $this->ezSQL->query($insertQuery);

        return  $this->ezSQL->insert_id;
	}

/**
* This method updates a record
* 
* @param $table: (Required) the table to use
* param $where: (Required) the where part of the query e.g. array('column'=>value)
* @param $values: (Required) an array of the values to save e.g. array('column'=>value)
*
* @return int
*/
	public function Update($table, $where, $values) {
		$where = $this->ColumnValueString($where, 'AND');
		$values = $this->ColumnValueString($values, ',');

		$update = "UPDATE $table SET $values WHERE $where";
        $this->ezSQL->query($update);

        return  $this->ezSQL->rows_affected;
	}

/**
* This method deletes records
* 
* @param $table: (Required) the table to use
* param $where: (Required) the where part of the query e.g. array('column'=>value)
*
* @return int
*/
	public function Delete($table, $where) {
		$where = $this->ColumnValueString($where, 'AND');

		$delete = "DELETE FROM $table WHERE $where";

        $this->ezSQL->query($delete);

        return  $this->ezSQL->rows_affected;
	}

/**
* This function performs a query on the table that represents the model
* It then return an array of objects or an array depending on the type of query performed.
* Except for $table other parameter can be either an array or a string
* When the parameter that is provided is a strng, it must not include the SQL keyword
* For example, if $where is a string, 
* it will be like "col1 = value, col2 = value" and NOT "WHERE col1 = value, col2 = value"
* 
* @param $table: (Required) The table to query
* @param $select: (Required) This could be a string or an array of the columns to be selected
* @param $where: (Optional) This is for the WHERE part of a query could be a string or an array 
* 							e.g. array('column'=>value)
* @param $grouping: (Optional) This is for the GROUP BY part of the query and is a string
* @param $having: (Optional) This is for the having part of the query and is a string
* @param $sort: (Optional) This is for the ORDER BY part of the query. It can be a string or
* 							an array e.g. array('column'=>'ASC')
* @param $limit: (Optional) This is for the LIMIT part of the query. It can be a string or 
* 							an array e.g. array('offset'=>0,'rows'=>30)
*
* @return array
*/
	public function Query($table, $select =null, $where =null, $grouping =null, $having =null, $sort =null, $limit =null) {
		$results = array();

		//Prepare the select part
		if(is_array($select)) {
			$select = $this->CommaSeparate($select);
		}

		$selectQuery = "SELECT $select FROM " . $table;

		//Prepare the where part
		if($where != null) {
			if(is_array($where)) {
				$where = $this->ColumnValueString($where, 'AND');
			}
			$selectQuery .= " WHERE $where";
		}
		
		//Prepare the grouping part
		if($grouping != null) {
			$selectQuery .= " GROUP BY $grouping";
		}
		
		//Prepare the having part
		if($having != null) {
			$selectQuery .= " HAVING $having";
		}
		
		//Prepare the Order by part
		if($sort != null) {
			if(is_array($sort)) {
				$sorttemp = '';
				foreach($sort as $k => $v) {
					$sorttemp .= "$k $v,";
				}
				$sort = substr($sorttemp, 0, -1);
			}
			$selectQuery .= " ORDER BY $sort";
		}
		
		//Prepare the limit part
		if($limit != null) {
			if(is_array($limit)) {
				$limit = $limit['offset'] . ", " . $limit['rows'];
			}
			$selectQuery .= " LIMIT $limit";
		}
		
		return $this->ezSQL->get_results($selectQuery,ARRAY_A);
	}

/**
* This function performs a query on the MySQL database
* 
* @param $q: (Required) Query
*
* @return resource
*/
	public function DirectQuery($q) {
        $query = $this->ezSQL->query($q);
        return $query;
    }

    function Clean($str) {
        $str = @trim($str);
        if(get_magic_quotes_gpc()) {
            $str = stripslashes($str);
        }
        return $this->mres($str);
    }

    function mres($value)
    {
        $search = array("\\",  "\x00", "\n",  "\r",  "'",  '"', "\x1a");
        $replace = array("\\\\","\\0","\\n", "\\r", "\'", '\"', "\\Z");

        return str_replace($search, $replace, $value);
    }

/**
* This method takes an array and then turns it into a string
* separating them with commas
* 
* @param $k: (Required)
*
* @return string
*/
	protected function CommaSeparate($k) {
		for($i = 0; $i < count($k); $i++) {
			$k[$i] = $this->Clean($k[$i]);
		}
		return  implode(', ', $k);
	}

/**
* This method takes an array and then turns it into a string
* separating them with commas. This one adds quoates to the string values
* 
* @param $v: (Required)
*
* @return string
*/
	protected function CommaSeparateWithQuotes($v) {
		for($i = 0; $i < count($v); $i++) {
			if(is_string($v[$i])) {
				$v[$i] = "'" . $this->Clean($v[$i]) . "'";
			} else {
				$v[$i] = $this->Clean($v[$i]);
			}
		}

		return  implode(', ', $v);
	}

/**
* This method takes an array and then turns it into a string
* separating them with commas or AND
* 
* @param $where: (Required) array to turn into a string e.g. array('column'=>value, column2'=>value)
* @param $separator: (Required)
*
* @return string
*/
	protected function ColumnValueString($where, $separator) {
		$separator = " $separator ";
		$return = '';
		foreach($where as $k => $v) {
			$return .= $this->Clean($k) . " = ";
			if(is_string($v)) {
				$return .= "'" . $this->Clean($v) . "'";
			} else {
				$return .= $v;
			}
			$return .= $separator;
		}

		return  substr($return, 0, -strlen($separator));
	}

}
Please help me

Re: Fatal error: Class 'ezSQL_mysql' not found

Posted: Thu Nov 17, 2016 10:35 am
by requinix
Did you install ezSQL? Are you making sure to execute the composer autoloads?