Search This Blog

MySQL Database Info

There are three information which you would like to have from MySQL.

Information about the result of queries: This includes number of records effected by any SELECT, UPDATE or DELETE statement.

Information about tables and databases: This includes information pertaining to the structure of tables and databases.

Information about the MySQL server: This includes current status of database server, version number etc.

Its very easy to get all these information at mysql prompt. BUt while using PERL or PHP APIs then we need to call various APIs explicitely to obtain all these information. Following section will show you how to obtain these information.

Obtaining the Number of Rows Affected by a Query:
PERL Example:
In DBI scripts, the affected-rows count is returned by do( ) or by execute( ), depending on how you execute the query:

# Method 1
# execute $query using do( )
my $count = $dbh->do ($query);
# report 0 rows if an error occurred
printf "%d rows were affected\n", (defined ($count) ? $count : 0);

# Method 2
# execute query using prepare( ) plus execute( )
my $sth = $dbh->prepare ($query);
my $count = $sth->execute ( );
printf "%d rows were affected\n", (defined ($count) ? $count : 0);