What are some potential pitfalls of using the mysql_query function in PHP for counting database entries?

Using the mysql_query function in PHP for counting database entries can lead to SQL injection vulnerabilities if user input is not properly sanitized. To avoid this issue, it's recommended to use prepared statements with parameterized queries instead.

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

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

// Prepare a statement
$stmt = $mysqli->prepare("SELECT COUNT(*) FROM table_name WHERE column_name = ?");

// Bind parameters
$stmt->bind_param("s", $column_value);

// Set parameters and execute
$column_value = "desired_value";
$stmt->execute();

// Bind result variables
$stmt->bind_result($count);

// Fetch result
$stmt->fetch();

// Output the count
echo "Count: " . $count;

// Close statement and connection
$stmt->close();
$mysqli->close();