我正在尝试第一次连接到mysql数据库。您能在下面看到什么无法正常工作吗?
我在第3行出现错误。
从Godaddy到数据库,我的服务器地址是什么样的?我在控制台中找到了该地址。

谢谢你的帮助。以前从未使用PHP进行编程。

<body>
<?php
 $con = mysql_connect("MydbName.db.3924516.hostedresource.com ","Userid","password");
 if (!$con)
 {
  die('Could not connect: ' . mysql_error());
 }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Gallerys");

echo "<table border='1'>
 <tr>
 <th>Thumb Url </th>
 <th>Gallery Url</th>
 </tr>";

while($row = mysql_fetch_array($result))
{
  echo "<tr>";
  echo "<td>" . $row['THUMBURL'] . "</td>";
  echo "<td>" . $row['GALLERYURL'] . "</td>";
  echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>

</body>

最佳答案

尝试重新检查身份验证设置,可能使用了错误的主机,用户名或密码。

    <?php
    $con = mysql_connect("usually it is localhost","your MYSQL username","your MYSQL password");

// Checking the login details.
// Example of default xampp login details: $con = mysql_connect("localhost","root","");
// Xampp MYSQL default does not have password.

    if (!$con) // If the login details are wrong, it will should an error.
      {
      die('Could not connect: ' . mysql_error());
      }
    ?>

关于php - 无法连接到MySQL DB,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12170117/

10-16 21:25