Created
December 19, 2017 07:14
-
-
Save hussnainsheikh/8bbc7236cc16139136ae2518b5b22f27 to your computer and use it in GitHub Desktop.
Simple PHP script to show columns name of a database table.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$db = 'Database'; //Database name | |
$host = 'Database_host'; //Hostname or Server ip | |
$user = 'USER'; //Database user | |
$pass = 'Password'; //Database user password | |
$con = mysql_connect($host,$user,$pass); | |
if($con){ | |
$link = mysql_select_db($db) or die("no database").mysql_error(); | |
$count = 0; | |
if($link){ | |
$sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$db' AND TABLE_NAME = 'table_name'"; // Change the table_name your own talbe name | |
$result = mysql_query( $sql, $con); | |
if(mysql_query($sql,$con)){ | |
echo $sql."<br> <br>"; | |
while ($row = mysql_fetch_row($result)) { | |
echo "COLUMN ".++$count.": {$row[0]}<br>"; | |
$table_name = $row[0]; | |
} | |
echo "<br>Total No. of COLUMNS: " . $count; | |
} | |
else{ | |
echo "Error in query."; | |
} | |
} | |
else{ | |
echo "Database not found."; | |
} | |
} | |
else{ | |
echo "Connection Failed."; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment