How can I efficiently highlight code snippets from text stored in a mySQL database using geshi in PHP?

To efficiently highlight code snippets from text stored in a mySQL database using geshi in PHP, you can retrieve the text from the database, pass it through geshi for syntax highlighting, and then display the highlighted code on your webpage. You can achieve this by using the following PHP code snippet:

<?php
// Connect to your MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Retrieve the text containing code snippets from the database
$sql = "SELECT code_snippet FROM your_table WHERE id = 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $code = $row["code_snippet"];
        // Include the GeSHi library
        require_once('geshi.php');
        
        // Create a new GeSHi object and specify the language
        $geshi = new GeSHi($code, 'php');
        
        // Display the highlighted code snippet
        echo $geshi->parse_code();
    }
} else {
    echo "0 results";
}

$conn->close();
?>