我的PHP腳本中出現了一個非常奇怪的錯誤。當我在腳本中包含外部文件並訪問包含文件中的某些變量時,每件事情都會在第一時間正常工作。當我將我的代碼封裝在一個函數中並嘗試從另一個PHP腳本調用該函數時,出現錯誤,指出某些變量未聲明(包含文件中的變量)。所以,當我包裝我的代碼在一個函數腳本無法找到外部變量時,當我不包裝在一個函數中的代碼每件事情工作正常......什麼會導致這個問題?當向腳本添加功能時,PHP不包含文件
編輯:
這裏是我的代碼,我定義的變量:
<?php
/* Database config */
$db_host = 'xxx';
$db_user = 'xxx';
$db_pass = 'xxx';
$db_database = 'xxxr';
/* End config */
$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_database);
// If you are connecting via TCP/IP rather than a UNIX socket remember to add the port number as a parameter.
?>
我想進入電影$ mysqli的
下面是其他代碼:
<?php
include "connect.php";
include "push.php";
function findActions($actionID,$userName)
{
$actionID = "X0aUsz7QOC1GCJG9ZnY0UoRWoj35hKFt0LxpwtB8";
$userName = "janne";
$currentDate = date('d/m/Y H:i');
$query = "SELECT * FROM ".$userName."actions WHERE actionID = ?";
if($stmt = $mysqli->prepare($query))
{
$stmt->bind_param('s', $actionID);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l);
while ($stmt->fetch())
{
$result[] = array($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l);
$startDate = strtotime($j);
$endDate = strtotime($i);
$now = time();
if ($now>= $startDate && $now<= $endDate)
{
$message = $e.":\n".$a;
$body['aps'] =
array(
'alert' => $message,
'sound' => 'default'
);
$payload = json_encode($body);
pushMessage($payload);
}
}
}
else
{
echo "Error";
}
}
?>
我與全球嘗試,但它並沒有幫助:(
請給出代碼 – user4035
[VARIABLE SCOPE!](http://www.php.net/manual/en/language.variables.scope.php) –