3

I've made a php script to access my database...as far as I can see all login details are right but I get this error message: Access denied for user 'a5247024_thesps'@'10.1.1.36' to database 'maininf'

<?php
// Make a MySQL Connection
mysql_connect("mysql11.000webhost.com", "a5247024_thesps", "******") or     die(mysql_error());
mysql_select_db("maininf") or die(mysql_error());

// Retrieve all the data from the "maininf" table
$result = mysql_query("SELECT * FROM maininf")
or die(mysql_error());  

// store the record of the "maininf" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry 

echo "Name: ".$row['PUA_Name'];


?>

Can anybody please help? Many thanks.

4

2 回答 2

5

您显然可能会将表名与数据库名混淆。除非您的表和数据库都被调用maininf否则您的调用mysql_select_db()可能需要一个不同的字符串作为数据库的实际名称,而不是表名。

// Your database name may not be the same as your table name!
// Substitute the correct value in place of maininf here
mysql_select_db("maininf") or die(mysql_error());

// Retrieve all the data from the "maininf" table
$result = mysql_query("SELECT * FROM maininf")
or die(mysql_error());  
于 2012-07-15T18:28:07.403 回答
0

我会先尝试使用这些凭据从 bash 访问 MySQL。

然后,尝试添加端口号:

例子:

mysql11.000webhost.com:3306

还要检查用户是否具有对数据库“maininf”的访问权限。您可以使用 MySQL 的SHOW GRANTS来查看数据库是否可供读取。

于 2012-07-15T18:27:53.217 回答