Your Ad Here

Home » mysql, PHP Code »

1

Hello friends,

The following script is for displaying the mysql connecting using php code and  table schema using php code.

It will be useful when we want to know the total fields of table.

1) Connecting with mysql :

$db_host     = “”;  // Database hostname
$db_username=”"; // Database username
$db_password=”"; // Database password
$db_name = “”; // Database name

$conn = mysql_connect($db_host,$db_username,$db_password) or die(“Could not connect to Server” .mysql_error());
mysql_select_db($db_name) or die(“Could not connect to Database” .mysql_error());

2) Write a query for the table which we want schema

$result = mysql_query(“SELECT * FROM {$tablename}”);
if (!$result) {
die(“Query to show fields from table failed”);
}

3) Getting the number of fields in that table

$fields_num = mysql_num_fields($result);

4) Display the table schema

for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo “<b>{$field->name}</b>”;

echo “<br>”;

}


You may like these posts

    How to request a cross domain ajax with in the js fileHow to build virtual keyboard for your web applicationSelect the age from birthday in mysql ?How to add or remove file fields using jquery

 

1 Comment

  1. Gojeg says:

    I have not played with myql + PHP anymore .. But, thanks for reminding me.

Leave a Reply