What are the potential risks of creating tables at runtime in PHP applications?

Creating tables at runtime in PHP applications can pose security risks such as SQL injection attacks if user input is not properly sanitized. To mitigate this risk, always validate and sanitize user input before using it to create tables dynamically. Additionally, consider using prepared statements or ORM libraries to interact with the database securely.

// Example code snippet to create a table at runtime securely
$pdo = new PDO("mysql:host=localhost;dbname=myDB", "username", "password");

// Sanitize user input before using it to create a table
$tableName = filter_var($_POST['table_name'], FILTER_SANITIZE_STRING);

// Prepare and execute a query to create the table
$stmt = $pdo->prepare("CREATE TABLE IF NOT EXISTS $tableName (id INT, name VARCHAR(50))");
$stmt->execute();