此代码从我的 Mac 运行,但不是从托管服务器运行。错误信息是:
Tue, 11 Jun 2013 14:46:48 -0700
Remote host: my_remoteserver.com
Remote user: my_user
Remote db: my_remotedbname
mysqli Failed to connect to MySQL: Access denied for user 'my_user'@'localsystem.com' (using password: YES)
出于某种原因,本地 apache/php 系统将“@localsystem.com”附加到我的用户 ID。我可以调整什么配置参数来防止这种情况发生?
从我的 Mac 运行时,输出如预期的那样:
Tue, 11 Jun 2013 18:03:41 -0400
mysqli Connection was OK!
Show databases returned 2 rows.
information_schema ()
my_remotedatabase ()
编码:
<?php
$hostname = "my_remoteserver.us";
$user = "my_user";
$password = "_today0613";
$dbname = "my_remotedbname";
echo date(r, time());
echo "Remote host: " . $hostname . "<br/>";
echo "Remote user: " . $username . "<br/>";
echo "Remote db: " . $dbname . "<br/>";
$con=mysqli_connect($hostname,$user,$password,$dbname);
// Check connection
if (mysqli_connect_errno($con))
{
echo "mysqli Failed to connect to MySQL: " . mysqli_connect_error();
} else { echo "mysqli Connection was OK!<br />\n";}
/* Select queries return a resultset */
if ($result = $con->query("SHOW databases")) {
printf("Show databases returned %d rows.<br />\n", $result->num_rows);
/* fetch object array */
while ($row = $result->fetch_row()) {
printf ("%s (%s)<br />\n", $row[0], $row[1]);
}
/* free result set */
$result->close();
}
$con->close();
?>