0

我知道这个问题可能已经被问了一百万次,但没有一个人解决了这个问题。我正在使用 PHP 连接到我的本地主机数据库,PHP 脚本如下所示:

<?php


// CONNECT TO THE DATABASE
$DB_NAME = 'users';
$DB_HOST = 'localhost';
$DB_USER = '********';
$DB_PASS = '********';
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword']; 

// A QUICK QUERY ON A FAKE USER TABLE
$query = "SELECT * FROM `members` WHERE `username`='$myusername' and `password`='$mypassword'";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

// GOING THROUGH THE DATA
if($result->num_rows == 1) {
header("location:login_success.php");
}
else {
header("location:fail.php");    
}
// CLOSE CONNECTION
mysqli_close($mysqli);

?>

这能够连接到数据库,但无法找到数据库“用户”。您可以从下面列出的图像中看到,该数据库存在,但找不到它。

http://i.imgur.com/xYvUCks.png

任何可以解决此问题的帮助将不胜感激!

4

2 回答 2

0

你可以试试这个phpmyadmin

GRANT SELECT, INSERT, DELETE ON database TO username@'localhost' IDENTIFIED BY 'password';

然后尝试运行您的 php 代码。

于 2013-07-07T07:19:41.233 回答
0

您正在将 OOP 接口mysqli与过程接口混合。

尝试这个:

$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);

if ($mysqli->connect_errno) {           // Changed to OOP version
  printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
于 2013-07-07T07:54:29.897 回答