我已经看了一个相关的答案这个问题的负载,但..解决方案仍然没有为我工作!我的代码在localhost测试环境内工作正常,但不在生产环境中。访问拒绝mysqli时推送到生产服务器
这里是我的代码:
<h1> Security clearances Due to Expire</h1>
<?php
$db['user'] = 'prometheus';
$db['password'] = '';
$db['host'] = '*****.manchester.mpl.local';
$ingeniumMySQL = new mysqli($db['host'], $db['user'], $db['password'], "ingenium");
if ($ingeniumMySQL->connect_errno) {
echo "Failed to connect to MySQL: " . $ingeniumMySQL->connect_error;
}
$sqlone="SELECT person_security_levels.clearance_expires_date,
person.forename,
person.surname
FROM person_security_levels, person
where person_security_levels.person_id= person.id and person_security_levels.clearance_expires_date between NOW() AND DATE_ADD(NOW() ,
INTERVAL +3 MONTH)
LIMIT 5000
";
$resultone= mysqli_query($ingeniumMySQL,$sqlone);
echo '<table id="magictable" style="float: left; margin: 0 30px 0 50px;">';
echo'<td colspan="3"><h3>Clearances Expiring within Three Months</h3></td>';
echo '</tr>';
echo '<tr>';
echo '<th class="headcolumn">Forename</th>';
echo '<th class="headcolumn">Surname</th>';
echo '<th class="headcolumn">Date Expires</th>';
echo '</tr>';
while ($row = mysqli_fetch_array($resultone)) {
echo "<tr><td>" . $row['forename'] . "</td><td>" . $row['surname'] . "</td><td>" . $row['clearance_expires_date'] . "</td></tr>";
}
echo "</table>";
$sqltwo="SELECT person_security_levels.clearance_expires_date,
person.forename,
person.surname
FROM person_security_levels, person
where person_security_levels.person_id= person.id and person_security_levels.clearance_expires_date between NOW() AND DATE_ADD(NOW() ,
INTERVAL +1 MONTH)
LIMIT 5000";
$resultwo= mysqli_query($ingeniumMySQL,$sqltwo);
echo '<table class="magictable" style="float: left; margin: 0 30px 0 50px;">';
echo'<td colspan="3"><h3>Clearances Expiring within One Month</h3></td>';
echo '</tr>';
echo '<tr>';
echo '<th class="headcolumn">Forename</th>';
echo '<th class="headcolumn">Surname</th>';
echo '<th class="headcolumn"> Date Expires</th>';
echo '</tr>';
while ($rows = mysqli_fetch_array($resultwo)) {
echo "<tr><td>" . $rows['forename'] . "</td><td>" . $rows['surname'] . "</td><td>" . $rows['clearance_expires_date'] . "</td></tr>";
}
echo "</table>";
$sqlthree="SELECT person_security_levels.clearance_expires_date,
person.forename,
person.surname
FROM person_security_levels, person
where person_security_levels.person_id= person.id and person_security_levels.clearance_expires_date between NOW() AND DATE_ADD(NOW() ,
INTERVAL+2 WEEK)
LIMIT 5000";
$resulthree= mysqli_query($ingeniumMySQL,$sqlthree);
echo '<table class="magictable" style="float: left; margin: 0 30px 0 50px;">';
echo'<td colspan="3"><h3>Clearances Expiring within Two Weeks</h3></td>';
echo '</tr>';
echo '<tr>';
echo '<th class="headcolumn">Forename</th>';
echo '<th class="headcolumn">Surname</th>';
echo '<th class="headcolumn"> Date Expires</th>';
echo '</tr>';
while ($roe = mysqli_fetch_array($resulthree)) {
echo "<tr><td>" . $roe['forename'] . "</td><td>" . $roe['surname'] . "</td><td>" . $roe['clearance_expires_date'] . "</td></tr>";
}
echo "</table>";
$sqlfour="SELECT person_security_levels.clearance_expires_date,
person.forename,
person.surname
FROM person_security_levels, person
where person_security_levels.person_id= person.id and person_security_levels.clearance_expires_date between NOW() AND DATE_ADD(NOW() ,
INTERVAL+7 DAY)
LIMIT 5000";
$resultfour= mysqli_query($ingeniumMySQL,$sqlfour);
echo '<table class="magictable" style="float: left; margin: 0 30px 0 50px;">';
echo'<td colspan="3"><h3>Clearances Expiring within Seven Days</h3></td>';
echo '</tr>';
echo '<tr>';
echo '<th class="headcolumn">Forename</th>';
echo '<th class="headcolumn">Surname</th>';
echo '<th class="headcolumn">Date Expires</th>';
echo '</tr>';
while ($roes = mysqli_fetch_array($resultfour)) {
echo "<tr><td>" . $roes['forename'] . "</td><td>" . $roes['surname'] . "</td><td>" . $roes['clearance_expires_date'] . "</td></tr>";
}
mysqli_close($ingeniumMySQL);
?>
我查询数据库来产生HTML表格的结果集。 授予指定用户全部权限 虚拟用户已创建用于在不同帐户上进行测试,并且使用最新的mysqli。
这里是在生产中显示的错误(欣赏任何建议):
警告:mysqli的:: mysqli的()[mysqli.mysqli]:(一千〇四十五分之二万八):访问 拒绝用户“普罗米修斯'@'****。manchester.mpl.local'(使用 password:YES) /storage/www/z-ingenium/application/views/scripts/reports/clearance-expires.phtml on line 7 Failed连接到MySQL:访问拒绝用户 'prometheus'@solutions.manchester.mpl.local'(使用密码:是)
看起来你没有在你的生产服务器上设置密码。尝试删除密码。 –
您是否从命令行验证了MySQL连接? (意识到在发布之前您可能已经从源代码中删除密码)。 –
您的数据库是否在另一台主机上?数据库服务器的“绑定地址”是否配置为允许远程主机?默认情况下,它只设置为允许从本地主机。 – Rvanlaak