gpt4 book ai didi

php - 超时错误和连接丢失

转载 作者:行者123 更新时间:2023-11-29 15:49:43 25 4
gpt4 key购买 nike

当我在本地主机服务器中运行代码时,它可以正常工作,但是当我们在实时服务器(Godaddy linux 共享服务器)中运行相同的代码时,它会给出 sql 连接失败错误。数据库相当大,在我们的本地服务器中查询大约需要 2 分钟才能返回数据,因此在共享的 godaddy 服务器中必须花费更多时间。

<?php
$conn = mysqli_connect("localhost","root","","doreme_eshop");

// $mysqli = new mysqli("localhost", "root", "", "doreme_eshop");
// if ($mysqli->connect_errno) {
// echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
// }

if(isset($_POST['submit'])){
$style=$_REQUEST['style_no'];
$result = mysqli_query($conn,"CALL style_report('".$style."')") or die("Query Failed: " . mysqli_error($conn));

//var_dump($result->fetch_assoc());

echo "<table border='1'>
<tr>
<th>total_set</th>
<th>style_no</th>
<th>size_id</th>
<th>size_description</th>
<th>Company_name</th>
<th>generate_no</th>
<th>order_Date</th>
<th>product_id</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['total_set'] . "</td>";
echo "<td>" . $row['style_no'] . "</td>";
echo "<td>" . $row['size_id'] . "</td>";
echo "<td>" . $row['size_description'] . "</td>";
echo "<td>" . $row['Company_name'] . "</td>";
echo "<td>" . $row['generate_no'] . "</td>";
echo "<td>" . $row['order_Date'] . "</td>";
echo "<td>" . $row['product_id'] . "</td>";
echo "</tr>";
}
echo "</table>";
}



?>
<html>
<head></head>
<body>
<form role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<select name="style_no" >
<option value="">STYLE NO</option>
<?php
$style_result = mysqli_query($conn,"CALL get_all_style_no()") or die("Query Failed: " . mysqli_error($conn));

$row1 = mysqli_num_rows($style_result);
while ($row1 = mysqli_fetch_array($style_result)){
echo "<option value='". $row1['style_no'] ."'>" .$row1['style_no'] ."</option>" ;
}
?>
</select>
<input type="submit" value="Submit" name="submit"/>
</form>
</body>
</html>

最佳答案

您需要设置连接超时,其次您可以将配置文件设置为分离和require_once。

尝试检查数据库是否有 mysqli 库,...只需打开连接然后关闭并检查错误

关于php - 超时错误和连接丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56834886/

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