gpt4 book ai didi

php - 不断出现 MySQLi 错误

转载 作者:行者123 更新时间:2023-11-30 01:00:01 24 4
gpt4 key购买 nike

当我尝试连接到 MySQLi 时,我不断收到此错误:

Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/1105): (proxy) all backends are down in /home/xylotk/public_html/Main/Header.php on line 5

Warning: mysqli::real_escape_string() [mysqli.real-escape-string]: Couldn't fetch mysqli in /home/xylotk/public_html/Main/Logged.php on line 5

Warning: mysqli::real_escape_string() [mysqli.real-escape-string]: Couldn't fetch mysqli in /home/xylotk/public_html/Main/Logged.php on line 6

Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in /home/xylotk/public_html/Main/Logged.php on line 7

Fatal error: Call to a member function fetch_array() on a non-object in /home/xylotk/public_html/Main/Logged.php on line 8

我不知道为什么会发生这种情况。我已尝试一切方法来修复它。

谁能至少向我解释一下这意味着什么?这就是导致错误的原因:

 global $mysqli;
$mysqli = new mysqli("localhost", "xylotk_chris", "-hidden-", "xylotk_database");

对于那些不断要求更多代码的人:

 include "Logged.php";
include "Login.php";

在这些文件(Logged.php)中:

<?php

$logged = false;
if($_COOKIE['xy_user'] && $_COOKIE['xy_salt']){
$xyuser = $mysqli->real_escape_string($_COOKIE['xy_user']);
$xysalt = $mysqli->real_escape_string($_COOKIE['xy_salt']);
$usrquery = $mysqli->query("SELECT * FROM `Accounts` WHERE `Salt`='$xysalt'");
$usr = $usrquery->fetch_array();
if($usr != 0){
if(hash("sha512", $usr['Username']) == $xyuser){
$logged = true;
}
}
}

?>

在 Login.php 中:

<?php

if($_POST['Login']){
if($_POST['existUsername'] && $_POST['existPassword']){

$Username = $mysqli->real_escape_string($_POST['existUsername']);
$Password = $mysqli->real_escape_string(hash("sha512", $_POST['existPassword']));

$userquery = $mysqli->query("SELECT * FROM `Accounts` WHERE `Username`='$Username'");
$user = $userquery->fetch_array();
if($user == '0'){

die('<div class="box boxerror">That username does not exist. You can still <a href="/Login/Register.php">register <b>' . $Username . '</b></a>. <a href="/" class="btn btn-danger">Go Back</a></div>');

}
if($user['Password'] != $Password){

die('<div class="box boxerror">The password entered was incorrect. <a href="/" class="btn btn-danger">Go Back</a></div>');
}

$Salt = hash("sha512", rand() . rand() . rand());
setcookie("xy_user", hash("sha512", $Username), time() + 24 * 60 * 60, "/");
setcookie("xy_salt", $Salt, time() + 24 * 60 * 60, "/");

$userID = $user['ID'];
$mysqli->query("UPDATE `Accounts` SET `Salt`='$Salt' WHERE `ID`='$userID'") or die($mysqli->error());

header('Location: /Dashboard');

}else{
die('<div class="box boxerror">You missed some fields! <a href="/" class="btn btn-danger">Go Back</a></div>');
}
}

?>

最佳答案

global $mysqli; 应该出现在 $mysqli = new mysqli“之后”...

解释一下:由于您尝试在连接之前将 $mysqli 设置为全局变量,因此无法工作,因为它尚未分配 ($mysqli)因此它超出了变量范围。

阅读有关该主题的 PHP 手册,了解有关全局变量的更多信息

关于php - 不断出现 MySQLi 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20222655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com