count colums and tables

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ranjitbd
Forum Newbie
Posts: 24
Joined: Sun May 03, 2009 1:59 pm

count colums and tables

Post by ranjitbd »

Code: Select all

 
// how to get the number of tables in a database in mysql
 
// how to get the total number of columns in a row 
 
 
 
User avatar
akuji36
Forum Contributor
Posts: 190
Joined: Tue Oct 14, 2008 9:53 am
Location: Hartford, Connecticut

Re: count colums and tables

Post by akuji36 »

Hello try this for your columns:

http://www.webmasterworld.com/forum88/10947.htm

mysql can show tables:

show tables

here:

http://dev.mysql.com/doc/refman/5.0/en/show-tables.html

thanks

Rod
ranjitbd
Forum Newbie
Posts: 24
Joined: Sun May 03, 2009 1:59 pm

Re: count colums and tables

Post by ranjitbd »

ranjitbd wrote:

Code: Select all

 
// how to get the number of tables in a database in mysql
 
// how to get the total number of columns in a row 
 
 
 
// i came to know that the number of tables in the database like 20, 30 or 40
// show tables column will show the table name...
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: count colums and tables

Post by AbraCadaver »

Code: Select all

// how to get the number of tables in a database in mysql
$result = mysql_query("SHOW TABLES FROM database_name");
$table_count = mysql_num_rows($result);
AND

Code: Select all

// how to get the total number of columns in a row
$result = mysql_query("SHOW COLUMNS FROM database_name.table_name");
$field_count = mysql_num_rows($result);
--or--

Code: Select all

// how to get the total number of columns in a row
$result = mysql_query("DESCRIBE database_name.table_name");
$field_count = mysql_num_rows($result); 
--or--

Code: Select all

// how to get the total number of columns in a row
$result = mysql_query("SELECT * FROM database_name.table_name LIMIT 1");
$field_count = mysql_num_fields($result); 
-Shawn
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply