php editor Apple today introduces how to use PHP code to list all databases in the MySQL server. MySQL is a popular relational database management system. The database in the MySQL server can be easily managed through PHP code. In this tutorial, we will demonstrate how to connect to a MySQL server and get a list of all databases, allowing you to quickly understand the database structure in the server. Let’s learn together!
List all databases in MySQL server
Using PHP
step:
$servername = "localhost"; $username = "root"; $passWord = "password"; $conn = new mysqli($servername, $username, $password);
SHOW DATABASES
Query: $result = $conn->query("SHOW DATABASES");
if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo $row["Database"] . "<br>"; } } else { echo "No databases found"; }
Full code example:
Other methods:
Use MySQL command line tools:
mysql -u root -p SHOW DATABASES;
Use phpMyAdmin tool:
The above is the detailed content of PHP lists all databases in MySQL server. For more information, please follow other related articles on the PHP Chinese website!