What are the alternatives to mysql_list_tables() in PHP for retrieving table information?
The mysql_list_tables() function is deprecated in PHP and should not be used for retrieving table information. Instead, you can use the mysqli extension or PDO to interact with MySQL databases and retrieve table information.
// Using MySQLi extension
$mysqli = new mysqli("localhost", "username", "password", "database_name");
$result = $mysqli->query("SHOW TABLES");
while($row = $result->fetch_row()) {
echo $row[0] . "<br>";
}
$mysqli->close();
```
```php
// Using PDO
$pdo = new PDO("mysql:host=localhost;dbname=database_name", "username", "password");
$result = $pdo->query("SHOW TABLES");
while($row = $result->fetch(PDO::FETCH_NUM)) {
echo $row[0] . "<br>";
}
$pdo = null;
Related Questions
- What are some best practices for handling errors and validating file types and sizes when uploading images using PHP?
- What are the advantages and disadvantages of using the mysql_fetch_array function versus the mysql_num_rows function for validating user credentials in PHP login systems?
- What are the best practices for creating a virtual container in Apache to deliver PHP 5 content alongside PHP 4 content?