What are the potential pitfalls of using the mysql_query function in PHP for retrieving table column properties?

The potential pitfalls of using the mysql_query function in PHP for retrieving table column properties include vulnerability to SQL injection attacks and deprecated usage of the mysql extension. To solve this issue, it is recommended to use parameterized queries with prepared statements and switch to the mysqli or PDO extension for improved security and functionality.

// Connect to the database using mysqli
$mysqli = new mysqli('localhost', 'username', 'password', 'database');

// Check connection
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

// Query to retrieve table column properties
$query = "SHOW COLUMNS FROM your_table_name";
$result = $mysqli->query($query);

if ($result) {
    while ($row = $result->fetch_assoc()) {
        echo "Column name: " . $row['Field'] . "<br>";
        echo "Data type: " . $row['Type'] . "<br>";
        // Add more properties as needed
    }
} else {
    echo "Error: " . $mysqli->error;
}

// Close connection
$mysqli->close();