Export Mysql Table Data in csv format through single query

Import and Export database or tables is really an important factor of coding and it is most important thing for every programmer. So sometimes we write lots of code to export any table from database in csv format. I am also a PHP programmer so I know these things. I found a good solution to export any table from database in csv format. Here is a query.

SELECT * FROM tablename INTO OUTFILE '/filename.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n’

So you can now easily export and table in csv format using above query in your code.

Generate Alpha Numeric number

Some times you want to generate Alpha Numeric , Numeric or Alphabetic digit for password or some kind of number. It can be 2 to 16 digit. For these problem i have a solutions:

function generateId($length, $type = 'ALPHANUMERIC') {

if($type == 'ALPHANUMERIC')
$chars = "12345CDEFGHI67890NOPQRSTU01492VWXYZ43210XYZFGH98765ABCDEF83574GHIJKLM09876QRSTUV54321";
else if($type == 'NUMERIC')
$chars = "1234567890987654321678905432101928374651029384756162738495061728394055432167890";
$id = "";
while (strlen($id)<$length) {
$id .= $chars{mt_rand(0,strlen($chars))};
}

return $id;

}

generateId(12,  'ALPHANUMERIC');