PHP函数不从外部文件打印


PHP function does not print from the external file

我有一个小问题。我有一个php函数,当它是在页面内完美地工作。在这里

$selectQuery = "SELECT DISTINCT product_code FROM product;";
$List = mysql_query( $selectQuery, $Connection ) or die("ERROR".mysql_error());
    while($Output = mysql_fetch_array($List))
    {
        echo "<option value='".$Output[0]."'>".$Output[0]."</option>";
    }

但是当我将它包含到我保留函数的文件中,然后从那里调用它时,它什么也不输出,下面的所有内容也不输出。下面是函数调用:

<select name="Selector" >
  <option value="">--Select Product--</option>
  <?php printProductBox("SELECT DISTINCT product_code FROM product;"); ?>
  </select>

这里是函数文件中的函数,它也包含在页面的前面:

function printProductBox($ParameterQuery){
     include ('DatabaseVariables.php');
     $List = mysql_query( $ParameterQuery, $Connection ) or die("ERROR".mysql_error());
     while($Output = mysql_fetch_array($List)){
        echo "<option value='".$Output[0]."'>".$Output[0]."</option>";
    }
}

数据库凭证文件包含在主页和函数文件中(函数文件也包含在页面中)。该文件中的其他函数在主页中工作。所以我想知道为什么这个函数有问题?

有人知道这事的线索吗?

把它放在函数的开头:

global $Connection;

使用新的建议编辑,如果连接已经建立,这可能会有帮助,尝试替换这些行的旧版本:

<?php printProductBox("SELECT DISTINCT product_code FROM product;", $Connection); ?>

function printProductBox($ParameterQuery, $Connection){

问题是缺乏凭据。凭据必须包含在函数作用域中。我想知道是否有一种方法来声明所有的变量全局。所以我不会在每个函数中都包含相同的文件。