PHP function within a function
<p>I created a simple function that needs to display some information.</p>

<p>Some of this information comes from the database.</p>

<p>But, the database handler is not recognized within this function, therefor, I get the following errors:</p>

<p><strong>Notice: Undefined variable: db in <em>censored</em>\controller\edit_mails.php on line 82</strong></p>

<p><strong>Fatal error: Call to a member function get_results() on null in <em>censored</em>\controller\edit_mails.php on line 82</strong></p>

<p>I'm using the ezSQL database handler</p>

<p>The function:</p>

<pre><code>function MessageSelector() {
$emails = $db-&gt;get_results("SELECT * FROM settings_emails WHERE cat = '$edit_type'" );
if(empty($emails)) {
//There are no messages to select
        } 
else { 
        //Create an option for each message
        foreach ($emails as $email):  
            echo "&lt;option value=\"", $email-&gt;title , "\" onclick=\"location.href='edit_emails.php?x=", $edit_type , "&amp;mail=",$email-&gt;id,"';\"&gt;", $email-&gt;title , "&lt;/option&gt;";
        endforeach;
        ";}  
}
</code></pre>

<p>Database Handler:</p>

<pre><code>require_once ADMIN_DB_DIR . '/ez_sql_core.php';
require_once ADMIN_DB_DIR . '/ez_sql_mysql.php';
global $db;
$db = new ezSQL_mysql($dbuser, $dbpassword, $dbname, $dbhost);
</code></pre>