Donec at mattis erat! Duis sed massa eget eros gravida vulputate nec ut ipsum.

Ron Bassett

Ron Bassett

Creating a md5(base64) or sha1(base64) password has in PHP

Last week I was trying to figure out how to get a 28 character md5. An application I was trying to generate passwords required what looked to be a 28 char hash.

First off I tried:

echo base64_encode(md5($password));

This returned way too many characters. After doing some research I found out it needs to be the binary out put of an md5. PHP 5+ has this option.

If the optional raw_output is set to TRUE, then the md5 digest is instead returned in raw binary format with a length of 16

To get the md5 binary format in php add TRUE to the md5() function.

Loading CSV files in MySQL

Many times you will want to load a csv file into a database. If your table is the same structure as the csv file there are some very quick ways to load the file into the db with out having to load it into an array and do foreach loops for each row. The LOAD DATA INFILE statement reads rows from a text file into a table at a very high speed. The file name must be given as a literal string.

LOAD DATA LOCAL INFILE "/location-of.csv" INTO TABLE csv.table FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'

Sometimes when exporting from a windose machine you will need to use the code below. Windows is bad about inserting poorly formated line breaks.

LOAD DATA LOCAL INFILE "/location-of.csv" INTO TABLE csv.table FIELDS OPTIONALLY ENCLOSED BY '\"' TERMINATED BY ',' LINES TERMINATED BY '\r\n'
Subscribe to this RSS feed

Latest News

Social GK5

Any data to display