Development Information

December 30, 2009

2.2.5 → 2.2.6

Filed under: Updates — judda @ 12:16 pm

Minor bug fix.  This will only affect people who have a NULL username or password for access to their database.

The class was originally not allowing it, but this has now been changed, along with some of the default values for database connection information.

December 23, 2009

Minor Issue in 2.2.5

Filed under: Updates — judda @ 12:00 pm

I found out that there was a minor typo in the released version 2.2.5.  So if you have downloaded a copy of it before now, please re-download the class in order to fix it.

The issue it was causing was in the use of the numRows function, it would just provide an error message and then be done with it.

December 21, 2009

2.2.4 → 2.2.5

Filed under: Updates — judda @ 1:31 am

Sorry for the long delay between updates.

The following things were changed:

  • freeResults now frees up all of the memory associated with the entire  results array
  • Added a function ‘getInsertId’ to retrieve the last insert id from the query
  • Removed PHP deprecated functions (replaced them with the functions which are going to stay)

December 20, 2009

Input Validation Class

Filed under: Validation Class Information — judda @ 6:49 pm

As mentioned yesterday, I started working on an input validation class in an attempt to make the validation of all input less tedious.  The first version of this class is complete.

Currently there are only four types of information which can be validated through this, but as time rolls on, I hope to add more to it making it more and more useful.

For starters, I would strongly suggest reading the documentation about the ‘validate’ function (click here for more information).

The following are the data types which are available:

  • length – check the minimum and/or maximum length of the input data
  • string - specify specific information about the actual string
  • integer - a number without any decimal points (defaults to signed)
  • decimal - a number with decimal places (defaults to signed)
  • real – same as decimal

For the data to be validated, the following two fields must also be present:

  • value – the value which needs to be validated
  • field - the name that this data will be referenced by

For each of the different types of checks, there are extra parameters (some optional, some required) which can help to ensure that your data is exactly what you want it to be.

The extra parameters are as follows:

length (a minimum of 1 of these parameters must be provided):

  • min – The minimum length that the value is allowed to have
  • max – The maximum length that the value is allowed to have

string (a minimum of 1 of these parameters must be provided):

  • alphabetic – Only allows letters of the alphabet in the text
  • alphanumeric – Only allows letters of the alphabet and numbers in the text
  • anything – Allows any kind of characters in the string
  • spaces – Allows for spaces to be in any of the text fields (combines with the three previous options)

integer:

  • min – The minimum value that the number is allowed to be
  • max – The maximum value that the number is allowed to be

decimal/real:

  • min – The minimum value that the number is allowed to be
  • max – The maximum value that the number is allowed to be

You may be wondering why this is all done in a class.   It is true that a class is not necessary however, it makes accessing it relatively convenient.  In order to reduce the overhead slightly, the function you call is static.  This means that you are able to access the function from outside of it, instead of needing to instantiate a copy of it before using the validate function.

How to use:

Step 1:

Include the validation class in the page (so PHP knows what it is).

require_once (/path/to/database/class/validate.php”);

Step 2:

Set up the arrays for the validation (this step can be skipped if you don’t mind placing arrays into the function call).

// outcome is the fact that the text provided is greater than the maximum
// allowed length as well as there is a number (it is alphanumeric not alphabetic)
// and that there is a space in the text
$validate1 = array (
	'value' => 'bo bo1',
	'field' => 'asdf',
	'length' => array ( 'max' => 3 ),
	'string' => array ( 'alphabetic' )
);
// outcome is the fact that the value is less than the minimum value
$validate2 = array (
	'value' => 5.5,
	'field' => 'asdf',
	'real' => array ( 'min' => 5.6, 'max' => 5.7 )
);

Step 3:

Call the validation function.  The validation function will return one of two things:

  • array – An array of issues which were found in the data provided
  • NULL – If no issues were found, meaning that the data meets the requirements
// Assuming that the variables from Step 2 were created
$issues = ValidateText::validate ( $validate1, $validate2 );
 
if ( $issues == NULL ) // Check if there were any issues
{
	echo ( 'No issues found.' );
}
else
{
	// Errors found, just do a quick dump of them all (you should deal with them differently)
	print_r ( $issues );
}

You have found all of the issues which were with the input data!

Please Note: You are able to provide the validate function with as many parameters as you desire, and it will process them all.  The output will be the accumulation of all issues which were found with the data.

Please let me know if you have any questions, comments or suggestions about this script and what else should be added into it.

December 19, 2009

Adding More Development Information

Filed under: Site Update — judda @ 11:00 pm

It has been decided that this blog will be used to list all of my things which are currently in development, not just the Database class.  However, it does not mean that I’ll be leaving the Database class behind, its just that I have a few more things that I want to get out there.  This includes a data validation class which I have been making recently.

This class is in early development but should end up being fairly useful to reduce the amount of time it takes to validate any kind of data in PHP.

I’ll add more information about it once I upload the first version of it.

Thanks.

Powered by WordPress