<commit_before><?
//

/*
todo:
add in more complete support stuff like changing users, passwords etc.

each driver class needs to have these functions and parameters:
	connect() //returns true if we connect
	prepare($sql) //returns true if it was prepaired
	query($sql) //actaully run the query
	results($sql) //return the results from the query
	escape($value) //escape a value useing the db's preferred way.
	$queries = an array of queries you have called so far
	$prepared = wether or not the current sql is prepared or not.
	$connection = the resource to the db.
	$settings = the settings used for the connection
*/
class My_SQL {
	
	var $prepared = false;
	
	var $queries = array();
	
	var $settings;
	
	var $connection;
	
	var $result;
	
	var $connected = false;
	
	function __construct($settings) {
		$this->settings = $settings;
	}
	
	function connect($settings=null) {
		//print_r($settings);
		if(isset($settings)) {
			$this->settings = $settings;
		}
	//	D::show($this->settings, 'newDB');
		//connects using our settings
		
/* 	@todo make the @ be able to be turned on and off by debug mode	 */
		$this->connection = @mysql_connect($this->settings['host'], $this->settings['username'], $this->settings['password']);
		mysql_set_charset('utf8');
		if (!$this->connection)	{
			D::warn("Couldn't to the db dude, check the settings man.\nHost: " . $this->settings['host'] . "\nUser: " . $this->settings['username'] . "\nDatabase: " . $this->settings['host']);
			return false;
		} else {
			if(!mysql_select_db($this->settings['databaseName'])) {
				D::warn('Could not select the database: ' . $this->settings['databaseName']);
				return false;
			}
			D::log($this->settings['databaseName'], 'Connected to the MYSQL database');
			$this->connected = true;
			return true;
		}
	}

	function prepare($sql) {
		//for now we don't actaully prepare our sql… i know i know.
		$this->prepared = true;
	}
	
	function test($value) {
		return $value . ' w00t, db data from any where using any kind of driver.';
	}
	
	function query($sql, $returnType=null) {
		if($this->prepared == false) {
			$this->prepare($sql);
		}
		//echo "\n SQL call = " . $sql . "\n";
		
		$this->queries[] = $sql;
	//	$this->result = $this->connection->query($sql);
		D::log("\n" . $sql, 'SQL call');
		
		$this->result = mysql_query($sql, $this->connection);
		
		$this->prepared = false;
		
		if(!$this->result) {
			D::stack();
			D::log(mysql_error($this->connection), 'SQL Errors');<commit_msg>made it display the sql on fail<commit_after><?
//

/*
todo:
add in more complete support stuff like changing users, passwords etc.

each driver class needs to have these functions and parameters:
	connect() //returns true if we connect
	prepare($sql) //returns true if it was prepaired
	query($sql) //actaully run the query
	results($sql) //return the results from the query
	escape($value) //escape a value useing the db's preferred way.
	$queries = an array of queries you have called so far
	$prepared = wether or not the current sql is prepared or not.
	$connection = the resource to the db.
	$settings = the settings used for the connection
*/
class My_SQL {
	
	var $prepared = false;
	
	var $queries = array();
	
	var $settings;
	
	var $connection;
	
	var $result;
	
	var $connected = false;
	
	function __construct($settings) {
		$this->settings = $settings;
	}
	
	function connect($settings=null) {
		//print_r($settings);
		if(isset($settings)) {
			$this->settings = $settings;
		}
	//	D::show($this->settings, 'newDB');
		//connects using our settings
		
/* 	@todo make the @ be able to be turned on and off by debug mode	 */
		$this->connection = @mysql_connect($this->settings['host'], $this->settings['username'], $this->settings['password']);
		mysql_set_charset('utf8');
		if (!$this->connection)	{
			D::warn("Couldn't to the db dude, check the settings man.\nHost: " . $this->settings['host'] . "\nUser: " . $this->settings['username'] . "\nDatabase: " . $this->settings['host']);
			return false;
		} else {
			if(!mysql_select_db($this->settings['databaseName'])) {
				D::warn('Could not select the database: ' . $this->settings['databaseName']);
				return false;
			}
			D::log($this->settings['databaseName'], 'Connected to the MYSQL database');
			$this->connected = true;
			return true;
		}
	}

	function prepare($sql) {
		//for now we don't actaully prepare our sql… i know i know.
		$this->prepared = true;
	}
	
	function test($value) {
		return $value . ' w00t, db data from any where using any kind of driver.';
	}
	
	function query($sql, $returnType=null) {
		if($this->prepared == false) {
			$this->prepare($sql);
		}
		//echo "\n SQL call = " . $sql . "\n";
		
		$this->queries[] = $sql;
	//	$this->result = $this->connection->query($sql);
		D::log("\n" . $sql, 'SQL call');
		
		$this->result = mysql_query($sql, $this->connection);
		
		$this->prepared = false;
		
		if(!$this->result) {
            D::show($sql);
			D::stack();
			D::log(mysql_error($this->connection), 'SQL Errors');
{'fraction_non_alphanumeric': 0.1659004597241655, 'fraction_numerical': 0.0011992804317409553, 'mean_word_length': 3.6247689463955637, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2343150', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1572, 'n_words': 490}