PHP / mySQLi错误1049:未知数据库

时间:2017-03-01 14:27:55

标签: php mysql mysqli

<!doctype HTML>
<head>

 <title>Soccer.db | The Ultimate Database for Soccer Stats, Info, & News</title>

  <link rel="stylesheet" href="football.css" />

</head>
 <body>

  <?php

  $host = "localhost";
  $username = "root";
  $password = "root";
  $db = "soccerdb";

   $db_con = new mysqli($host, $username, $password, $db);

   if ($db_con->connect_errno) {
     echo "Failed to connecto to MySQL: (" . $db_con->connect_errno . ") " .     $db_con->connect_error;
  }
  echo $db_con->host_info . "\n";

   $result = mysqli_query($db_con, "SELECT * FROM players");

   $db_con->close();

   ?>
 <div class="top-nav-wrapper">
   <div class="top-nav-content">
     <span>Soccer.db</span>
  </div>
</div>
 <div class="long-ad-wrapper">
  <div class="long-ad-content">

  </div>
 </div>
<?php

  echo "<table>";

 while($row = mysqli_fetch_array($result)){
   echo "<tr><td>" . $row['firstname'] . "</td><td>" . $row['lastname'] . "</td>          <td>" . $row['age'] . "</td></tr>";

 echo "</table>";
 }
?>
</body>

我收到错误1049我的数据库不存在,虽然使用phpmyadmin,我确定它存在。我还阅读了一些建议并尝试更改名称,但仍然无效。感谢。

编辑:Pic of phpmyadmin绝对没有空格和大写是正确的。 Root是密码,当我将其更改为&#39;时它会断开连接。 &#39;

1 个答案:

答案 0 :(得分:0)

您是否可以尝试将主机更改为&#34; 127.0.0.1&#34;,以查看是否有所作为? 我知道这看起来很傻,但其他人之前也遇到过麻烦。 请参阅:Mysql localhost!= 127.0.0.1?