function: Use MySQL and mysqli two ways to connect to the database to get all the tables in all databases and libraries on the MySQL server.
Environment: Use separate installation of Apache MySQL PHP built Environment
Operating system is: Windows 10
The code is as follows:
<?php
/**
* mysqli op mysql Demo
*/
/**
* Common functions
*/
/**
* function: List all tables of a database
* @param$dbname
* @param$con
*/
functionList_tables($dbname,$con)
{
mysql_select_db ($dbname,$con) or die("failed to select Database!");
$res= mysql_query ("SHOW TABLES");
$tables= Array();
while($row= Mysql_fetch_array ($res))
{
Echo$row[0] .' <br> ';
}
Mysql_free_result ($res);
//return $tables;
}
/**
* UseMSYQLmethod to get the names of all libraries
*/
$mysqlCon= mysql_connect (' localhost ',' Root ',' + ');
$set= mysql_query (' SHOW DATABASES; ');
$dbs= Array();
while($db= Mysql_fetch_row ($set))
$dbs[] = $db[0];
//var_dump ($dbs);
Echo' this isMySQLresults of the operation output:;
//print_r ($dbs);
/**
* This is used to display the database name
*/
foreach($dbs as$key=$value){
Echo' <b> '.$key. "=". $value.' </b><br> ';
List_tables ($value,$mysqlCon);
}
Echo' this isMsyqliresults of the operation output:;
$mysqliCon= Mysqli_connect (' localhost ',' Root ',' + ');
$result= Mysqli_query ($mysqliCon,' show databases ');
$dbs 2=Array();
while($db=mysqli_fetch_row ($result))
$dbs 2[] = $db[0];
Print_r ($dbs 2);
The results are as follows:
This is the result of the MySQL operation output:
0=>information_schema
Character_sets
Collations
Collation_character_set_applicability
COLUMNS
Column_privileges
ENGINES
EVENTS
FILES
Global_status
Global_variables
Key_column_usage
PARAMETERS
Partitions
PLUGINS
Processlist
PROFILING
Referential_constraints
ROUTINES
Schemata
Schema_privileges
Session_status
Session_variables
STATISTICS
TABLES
Tablespaces
Table_constraints
Table_privileges
TRIGGERS
User_privileges
Views
Innodb_buffer_page
Innodb_trx
Innodb_buffer_pool_stats
Innodb_lock_waits
Innodb_cmpmem
innodb_cmp
Innodb_locks
Innodb_cmpmem_reset
Innodb_cmp_reset
Innodb_buffer_page_lru
1=>access_control
Collection
Collection2permission
Permission
Signup
User
User2collection
2=>db_bcty365
Tb_bb
Tb_bbqb
Tb_bbs
Tb_bccd
Tb_bccdjj
Tb_city
Tb_cjwt
Tb_dd
Tb_leaveword
Tb_reply
Tb_sjxz
Tb_soft
Tb_tell
Tb_type
Tb_type_big
Tb_type_small
Tb_user
Tb_xlh
3=>db_nethard
Tb_member
Tb_upfile
Tb_uptype
4=>db_reglog
Tb_member
5=>mysql
Columns_priv
Db
Event
Func
General_log
Help_category
Help_keyword
Help_relation
Help_topic
Host
Ndb_binlog_index
Plugin
Proc
Procs_priv
Proxies_priv
Servers
Slow_log
Tables_priv
Time_zone
Time_zone_leap_second
Time_zone_name
Time_zone_transition
Time_zone_transition_type
User
6=>performance_schema
Cond_instances
Events_waits_current
Events_waits_history
Events_waits_history_long
Events_waits_summary_by_instance
Events_waits_summary_by_thread_by_event_name
Events_waits_summary_global_by_event_name
File_instances
File_summary_by_event_name
File_summary_by_instance
Mutex_instances
Performance_timers
Rwlock_instances
Setup_consumers
Setup_instruments
Setup_timers
Threads
7=>php_study
8=>phpbook
AddressBook
9=>regi
Member
10=>test
11=>world
City
Country
Countrylanguage
This is the result of the msyqli operation output:
Array ([0] = information_schema [1] = Access_control [2] = db_bcty365 [3] = = Db_nethard [4] = Db_reglog [5] = = MySQL [6] = Performance_schema [7] = php_study [8] = = Phpbook [9] => ; Regi [Ten] = Test [one] = world)
Use MySQL and mysqli to get all the tables in MySQL's database and library