[ create a new paste ] login | about

Link: http://codepad.org/StiiHUUe    [ raw code | fork ]

PHP, pasted on Jul 26:
/**
	 * Function to write the log messages in DB.
	 * @param Array $args	Array of messages as given by the user to be written in log files.
	 */
	public function log($args)
	{
		$logValues = $this->changeTemplate($args);	//change the user given message appropriate to the template of the log files. This is necessary to maintain consistency among all the log files.
		
		$noOfEntries = count($this->template);	//get the how many entries are in the template. This is same as number of columns present in the DB and this helps in preparing the SQL statement.
		
		//Prepare the SQL statement.
		$SQLStatement = "INSERT INTO " . $this->dbConfig['tablename'] . " (";
		foreach ($this->template as $key=>$value)
		{
			$SQLStatement = $SQLStatement . $key . ",";	//Add all the column names.
		}
		$SQLStatement = substr($SQLStatement, 0, -1) . ") VALUES (";
		for($i = 0; $i < $noOfEntries; $i = $i + 1)
		{
			$SQLStatement = $SQLStatement . "?,";	//Add as many "?" as there are number of columns.
		}
		$SQLStatement = substr($SQLStatement, 0, -1) . ")";
		
		$values = array();
		foreach ($logValues as $k=>$v)
		{
			array_push(&$values, $v);	//create an array that contains values for all columns.
		}
		
		SQL($SQLStatement, $values);	//execute the SQL statement.
	}


Create a new paste based on this one


Comments: