Powerful PHP can use the relevant functions of MySQL interaction to get data table field information, such as can get data table get field name, field length, field information and so on.
The powerful PHP tutorials can take advantage of the MySQL tutorial interaction's related functions to get the data table field information, such as can get the data table get field name, field length, field information and so on.
*/
$hostname = "localhost"; Define the name of the MySQL server to which you are connected
$username = "root"; Define the user name to use for the connection
$password = ""; Define the password to use for the connection
$link =mysql_connect ($hostname, $username, $password); Open MySQL Connection
$db _list=mysql_list_dbs ($link); List Database Tutorials
$rows =mysql_num_rows ($db _list); Get the number of results returned
$i = 0;
while ($i < $rows)//Iterate through the result set and assign a value to the object
{
Echo mysql_db_name ($db _list, $i). " n "; Output Object Content
echo "
n ";
$i + +;
}
Mysql_close ($link); Close MySQL Connection
Returns the length of a column
$sql _str= "SELECT * from friends where id=1"; Defining SQL statements
$result =mysql_query ($sql _str); Execute SQL statement
$re _a=mysql_fetch_array ($result);
$re _len=mysql_fetch_lengths ($result);
for ($i =0; $i<>
{
echo "Returns the result of". $i. " The length of the column is: ". $re _len[$i];
echo "
";
}
Mysql_close ($link);
Get field information
$result =mysql_query ("select * from friends"); Execute SQL query
/* Get field information */
$i = 0;
while ($i
{
$i + +;
echo "First". $i. " Columns of information:
n ";
$meta =mysql_fetch_field ($result); Get field information
if (! $meta)//If the value does not exist
{
echo "No information available
n "; No information available for output
}
echo "
Blob:
Max_length: $meta->max_length
Multiple_key: $meta->multiple_key
Name: $meta->name
Not_null: $meta->not_null
Numeric: $meta->numeric
Primary_key: $meta->primary_key
Table: $meta->table
Type: $meta->type
Unique_key: $meta->unique_key
Unsigned: $meta->unsigned
Zerofill: $meta->zerofill
"; End to format output
}
The Mysql_field_flags () function obtains the flags associated with the specified field from the result.
$re _field=mysql_field_flags ($result, 0);
$flag =explode ("", $re _field);
Print_r ($flag);
$re _field=mysql_field_flags ($result, 1);
$flag =explode ("", $re _field);
Column Name
$result =mysql_query ($sql _str); Execute SQL statement
$re _name=mysql_field_name ($result, 0); Gets the name of the first field
echo "The first field is named:". $re _name;
echo "
";
$re _name=mysql_field_name ($result, 1); Get the name of a second field
echo "The second field has a name of:". $re _name;
echo "
";
$re _name=mysql_field_name ($result, 2); Get the name of a third field
echo "The third field has a name of:". $re _name;
echo "
";
$re _name=mysql_field_name ($result, 3); Gets the name of a fourth field
echo "The fourth field is named:". $re _name;
echo "
";
$re _name=mysql_field_name ($result, 4); Gets the name of a fifth field
echo "The fifth field is named:". $re _name;
echo "
";
http://www.bkjia.com/PHPjc/630773.html www.bkjia.com true http://www.bkjia.com/PHPjc/630773.html techarticle powerful PHP can use the relevant functions of MySQL interaction to get data table field information, such as can get data table get field name, field length, field information and so on. Powerful PHP Tutorials ...