当我在localhost服务器中运行代码时,它可以正常工作,但是当我们在实时服务器(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>
答案 0 :(得分:0)
您需要设置连接超时,其次您可以将配置文件设置为require_once分开。
尝试检查数据库是否具有mysqli库,...仅打开连接,然后关闭并检查错误