如何修复PHP中的“无法重新声明”错误?

时间:2019-04-13 06:25:49

标签: php

当语言字符串为“ en”时,出现此错误:

Fatal error: Cannot redeclare getSetting() (previously declared in /Users/manuel/Sites/WebApply/datamanager.php:2) in /Users/manuel/Sites/WebApply/datamanager.php on line 10

我已经尝试将require导入更改为require_once,但是没有成功。

index.php

if(!file_exists("mysql.php")){
  header("Location: setup/index.php");
  exit;
}
require_once("datamanager.php");
require_once('assets/languages/lang_'.getSetting("lang").'.php');

datamanager.php

<?php
function getSetting($setting){
  require_once("mysql.php");
  $stmt = $mysql->prepare("SELECT * FROM settings WHERE NAME = :setting");
  $stmt->bindParam(":setting", $setting, PDO::PARAM_STR);
  $stmt->execute();
  while ($row = $stmt->fetch()) {
    return $row["VALUE"];
  }
}
function setSetting($setting, $value){
  require_once("mysql.php");
  $stmt = $mysql->prepare("UPDATE settings SET VALUE = :value WHERE NAME = :setting");
  $stmt->bindParam(":setting", $setting, PDO::PARAM_STR);
  $stmt->bindParam(":value", $value, PDO::PARAM_STR);
  $stmt->execute();
}
function getRankID($username){
  require_once("mysql.php");
  $stmt = $mysql->prepare("SELECT * FROM accounts WHERE USERNAME = :user");
  $stmt->bindParam(":user", $username, PDO::PARAM_STR);
  $stmt->execute();
  while ($row = $stmt->fetch()) {
    return $row["USERRANK"];
  }
}
 ?>

0 个答案:

没有答案