未找到所需文件的变量

时间:2014-07-27 07:23:40

标签: php mysqli require

MySQLiconfig.php:

<?php
$MySQLi   = new mysqli('localhost','root','123','Database') or die('ERROR');

其他文件:

<?php
require 'MySQLiconfig.php';

function DoAQuery($Query){
   $MySQLi->query($Query);
}

错误是:

 Undefined variable: MySQLi

1 个答案:

答案 0 :(得分:-1)

你变量范围错了。在您需要使用的函数global $MySQLi中,或者您可以作为函数参数传递。