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"