4.2.29. MySQL metadata

发布时间 :2025-10-25 12:31:21 UTC      

You may want to know the following three messages about MySQL:

  • 查询结果信息: The number of records affected by the SELECT, UPDATE, or DELETE statement.

  • 数据库和数据表的信息: It contains the structure information of database and data table.

  • MySQL服务器信息: Contains the current status of the database server, version number, and so on.

From 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 call a specific interface function to get it. We will introduce it in more detail next.

Get the number of records affected by the query statement

PERL instance

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

# 方法 1
# 使用do( ) 执行  $query
my $count = $dbh->do ($query);
# 如果发生错误会输出 0
printf "%d 条数据被影响\n", (defined ($count) ? $count : 0);

# 方法 2
# 使用prepare( ) 及 execute( ) 执行  $query
my $sth = $dbh->prepare ($query);
my $count = $sth->execute ( );
printf "%d 条数据被影响\n", (defined ($count) ? $count : 0);

PHP instance

In PHP, you can use the mysqli_affected_rows( ) Function to get the number of records affected by the query statement.

$result_id = mysqli_query ($conn_id, $query);
# 如果查询失败返回
$count = ($result_id ? mysqli_affected_rows ($conn_id) : 0);
print ("$count 条数据被影响\n");

List of databases and datasheets

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

You can also use SHOW TABLES or SHOW DATABASES statements to get lists of databases and tables.

PERL instance

# 获取当前数据库中所有可用的表。
my @tables = $dbh->tables ( );
foreach $table (@tables ){
   print "表名 $table\n";
}

PHP instance

The following example outputs all databases on the MySQL server:

View all databases

<?php$dbhost='localhost';//mysql服务器主机地址$dbuser='root';//mysql用户名$dbpass='123456';//mysql用户名密码$conn=mysqli_connect($dbhost,$dbuser,$dbpass);if(!$conn){die('连接失败:'.mysqli_error($conn));}//设置编码,防止中文乱码$db_list=mysqli_query($conn,'SHOW
DATABASES');while($db=mysqli_fetch_object($db_list)){echo$db->Database."<br
/>";}mysqli_close($conn);?>

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 statu

SHOW VARIABLES

Server configuration variable

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.