MySQL meta data "1"

Source: Internet
Author: User

MySQL Meta Data

You may want to know the following three kinds of information about MySQL:

    • Query Result information: The number of records affected by the SELECT, UPDATE, or DELETE statement.
    • Database and data table information: contains the structure information of the database and the data table.
    • MySQL server information: contains the current state of the database server, the version number, and so on.

In the MySQL command prompt, we can easily get the above server information. But if you use a scripting language such as Perl or PHP, you need to invoke a specific interface function to get it. We'll cover it in more detail next.

Get the number of records affected by a query statement Perl instance

In the DBI script, the number of records affected by the statement is returned through the function do () or execute ():

# method 1# Use Do () to perform $queryMy$count=$dbh-Do ($query);# output 0 If an error occursPrintf"%d rows were affected\n", (Defined ($count) ?$count: 0);# method 2# Execute $query using prepare () and execute ()My$sth= $dbh-Prepare ($query);  My $count = execute ( ) , $sth printf "%d rows were affected\n", (defined ($count) ? $ Count : 0);               
PHP instance

In PHP, you can use the Mysql_affected_rows () function to get the number of records affected by a query statement.

=($query, $conn _id);  =(? ($conn _id):0);  Print("$count rows were affected\n");           
Database and data table lists

You can easily get a list of databases and data tables in the MySQL server. If you do not have sufficient permissions, the result will return NULL.

You can also use the show TABLES or show DATABASES statements to get a list of databases and data tables.

PERL instances
# gets all the tables available in the current database.  my@tables= $dbh, ();  foreach(@tables) {print"Table Name $table \ n";}      
PHP instance
<?Php$con=Mysql_connect("LocalHost", "UserID", "Password");If (!$con){ Die(' Could not connect: ' .Mysql_error());} $db _list = Mysql_list_dbs (  $con ); while  ( $db = Mysql_fetch_object ( $db _list { echo $db ->database . "<br/>" ;}mysql_close ( $con ?>            
Get Server metadata

The following command statements can be used at the command prompt in MySQL, or in scripts such as PHP scripts.

Command Description
SELECT VERSION () Server version Information
SELECT DATABASE () Current database name (or return empty)
SELECT USER () Current user name
SHOW STATUS Server Status
SHOW VARIABLES Server Configuration variables

MySQL meta data "1"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.