Updates from admin RSS Toggle Comment Threads | Keyboard Shortcuts

  • admin 4:30 pm on June 18, 2010 Permalink  

    Input Validation 

    A simple PHP function for INPUT validation.

    function check_chars($variable,$what,$min_length, $max_length,$bad_chars){ 
    	if (strlen($variable) < $min_length || strlen($variable)  > $max_length) {
    		die("$what is not the correct number of chars or is missing.");
    	} else if (preg_match("/$bad_chars/i", $variable)) {
    		die("Incorrect chars in $what.");
    	} else {
    		echo "Successful type constraint check for $what.<br \>";
    	}
     
    	$variable= mysql_real_escape_string($variable); //a good place to escape anything suspicious that might have left.
    	return $variable;
    }
     
    //example usage
     
    check_chars($first_name,'First name',2,25,"[^a-z]"); //names should be longer than 2 and less than 25 chars
    check_chars($middle_initial,'Middle name',1,1,"[^a-z]"); //we want only the first char from the name
    check_chars($address,'Address',2,100,"[^a-z0-9-, ]"); //this could be probably improved
    check_chars($city,'City',2,25,"[^s-zA-Z]"); 
    check_chars($state,'State',2,2,"[^A-Z]");
    check_chars($zip,'Zip',5,5,"[^0-9]");
     
  • admin 11:50 am on June 16, 2010 Permalink
    Tags: getty images, scam   

    Getty Images Scam? 

    Is Getty Images a scam? It seems so from most posts on the net and if you have problems with them read these:

    http://internetmadness.blogspot.com/2007/06/getty-images-are-trying-to-getty-me.html

    http://www.zyra.info/getstu.htm

    Whether Getty is a scam or not remains a question to all. Their claims don’t have legal basis and I don’t think they have ever successfully sued anyone.

     
  • admin 7:42 pm on June 5, 2010 Permalink
    Tags: database normalization,   

    MySQL Normalization 

    Database normalization prevents redundancy, inconsistency and data loss. It includes several steps as follows:

    1. 1NF – First Normal Form states that all tuple values should be atomic. Atomic means that there should be only one useful piece of data for each attribute.

    The first step in database normalization is to determine the functional dependencies in the database. This means to find which values are determined by which.

    2. Decomposition and Boyce/Codd Normal Form

    BCNF has only one requirement – every functional dependency must be functionally determined by either a candidate key*, or a superset of a candidate key( superkey).

    *A candidate key is a set of attributes that must be unique for each tuple and irreducible into a smaller key.

    Example:

    candidate_key -> value

    candidate_key2 -> value2

    5. 5th Normal Form requires that each join dependency is satisfied by superkeys.

    join dependency(JD) is a set of projections on a relation which when joined reform the original relation.

     
  • admin 7:28 pm on May 24, 2010 Permalink  

    Relational Theory 

    The difference between relvar and relation:

    A relation is a value, filled with all the attribute and tuple values. On the other hand a relvar is a variable associated with some representation of a relation.

    The difference between a base relation and a view:

    Base relation is the original value while a view is deducted from it by a certain criteria (select statement).

     
  • admin 7:06 pm on May 23, 2010 Permalink
    Tags: csv, INTO OUTFILE, LOAD DATA,   

    Text Files and MySQL databases 

    If for some strange reason you have to import CSV file directly into MySQL here is a good query to go:

    mysql> LOAD DATA INFILE ‘file.csv’ INTO TABLE table_name FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY ‘”‘ LINES TERMINATED BY ‘\r\n’ (column1, column2);

    It gives you all the options such as how fields are terminated, enclosed and so on. The above example is specific for a csv file created with a Windows Text Editor. (windows… haha)

    Similarly, if you have to export a query into a text file here is how this can be done:

    mysql> SELECT column1, column2 INTO OUTFILE ‘file.csv’ FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY ‘”‘LINES TERMINATED BY ‘\r\n’ FROM table_name;

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel