Wednesday, March 30, 2011

Show MySql database table's column name with type

Show MySql database table's column name with type.

Situation where you want to work with mysql database's table in php
for ex: showing records etc  and you don’t have the access information
of mysql database and don't know the column names.
You only are having FTP Information. 
In this tough condition you can do the your job.
Here is the code that will show maysql database table’s column full information.

< ? php
    $host = "Server-IP-Here";
    $user = "Database-User-Id-Here";
    $password = "Database-User-Ids-Password-Here";
    $database = "Database-Name";
    $serverLink = mysql_connect($host,$user,$password);
    mysql_select_db($database,$serverLink);
    //$ssql = "SHOW COLUMNS FROM Table-Name-Here";
    $ssql = "SHOW COLUMNS FROM office_mast";
    $rs = mysql_query($ssql);
    while($col = mysql_fetch_array($rs, MYSQL_BOTH)) {
        print_r($col);
        echo "
";
    }
    mysql_free_result($rs);
    mysql_close($serverLink);
? >

No comments:

Post a Comment