Search This Blog

Tuesday 19 March 2013

Database table fields type using PHP

 Script to list all the field data types in specified database and create a CSV file then download the CSV file.

<?php
set_time_limit(0);
getUniqueFieldTypes('HOSTNAME','DATABASE USERNAME','PASSWORD','DATABASENAME');

function getUniqueFieldTypes($host,$user,$pass,$name,$tables = '*')
{
   
    $link = mysql_connect($host,$user,$pass) or die('Could not connect');
    mysql_select_db($name,$link);
   
    //Get all of the tables
    if($tables == '*')
    {
        $tables = array();
        $result = mysql_query('SHOW TABLES');
        while($row = mysql_fetch_row($result))
        {
            $tables[] = $row[0];
        }
    }
    else
    {
        $tables = is_array($tables) ? $tables : explode(',',$tables);
    }
    $dataTypes = array();
    //Cycle through
    foreach($tables as $table)
    {
        $result = mysql_query('SHOW FIELDS FROM '.$table);
        $num_fields = mysql_num_fields($result);
   
        while($row = mysql_fetch_row($result))
        {
            $dataTypes[$row[1]] = $row[1];
        }
        //sleep(1);
    }
    asort($dataTypes);

    $fp = fopen('fields.csv', 'w+');
    foreach($dataTypes as $dataType) {
        $values = array($dataType);
        fputcsv($fp, $values);
    }
   fclose($fp);
   $file = 'fields.csv';
   
    if (file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
        exit;
    }
   
}
?>
<html>
    <head>
        <title>Create CSV with list of field data types</title>
    </head>
</html>

Below are the list data types supported by MYSQL:
VARCHAR
TINYINT
TEXT
DATE
SMALLINT
MEDIUMINT
INT
BIGINT
FLOAT
DOUBLE
DECIMAL
DATETIME
TIMESTAMP
TIME
YEAR
CHAR
TINYBLOB
TINYTEXT
BLOB
MEDIUMBLOB
MEDIUMTEXT
LONGBLOB
LONGTEXT
ENUM
SET
BOOL
BINARY
VARBINARY
 

Thursday 7 March 2013

Installing Magento via SSH

Working with CentOS Command line


Tutorial on working with CentOS:http://www.rackspace.com/knowledge_center/article/choosing-a-linux-distribution
http://www.rackspace.com/knowledge_center/article/centos-54

Installing Apache and PHP:
http://www.rackspace.com/knowledge_center/article/centos-apache-and-php-install

Installing MYSQL:
http://www.rackspace.com/knowledge_center/article/installing-mysql-server-on-centos

Installing Wordpress:
http://blog.adlibre.org/2010/03/10/how-to-install-wordpress-on-centos-5-in-five-minutes-flat/

Installing phpMyAdmin:
http://www.krizna.com/centos/how-install-phpmyadmin-centos-6/

Setup Virtual Hosts:
http://www.rackspace.com/knowledge_center/article/centos-apache-virtual-hosts#Create_the_Directory_Layout
OR
http://www.rackspace.com/knowledge_center/article/how-to-serve-multiple-domains-using-virtual-hosts

Setup Cron JOBs:
http://keertikiran.blogspot.in/2012/05/manage-cron-job-using-putty.html

Compressing and uncompressing the Files:
http://www.centos.org/docs/4/html/rhel-sbs-en-4/s1-managing-compressing-archiving.html

Database Export and Import commands:
http://keertikiran.blogspot.in/search/label/Putty