// Connect to database $conn = new mysqli("localhost", "username", "password", "database_name"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Get table names $tables = array(); $result = $conn->query("SHOW TABLES"); while($row = $result->fetch_array()) { $tables[] = $row[0]; } // Print table names print_r($tables); // Close connection $conn->close();
// Connect to database $conn = new PDO("mysql:host=localhost;dbname=database_name", "username", "password"); // Insert data into table $stmt = $conn->prepare("INSERT INTO users (name, email) VALUES (:name, :email)"); $stmt->bindParam(':name', $name); $stmt->bindParam(':email', $email); $name = "John Doe"; $email = "john.doe@example.com"; $stmt->execute(); // Close connection $conn = null;In this example, we connect to a database using PDO and insert data into a table named "users". We prepare a statement with placeholders for the values and bind parameters to the statement. Finally, we execute the statement with the values. Package/Library: PDO These are just a few examples of how PHP can be used to work with database table names. There are many other functions and tools available in PHP to interact with databases, depending on the database technology being used. Some popular database libraries for PHP include PDO, mysqli, and MySQLi.