当前位置: 动力学知识库 > 问答 > 编程问答 >

database - I have more than one error getting from my php code connecting to my server

问题描述:

Errors are Warning:

mysql_connect() [function.mysql-connect]: Access denied for user

'test'@'10.1.1.23' (using password: YES) in

/home/a4228948/public_html/imageid.php on line 9

Warning: mysql_select_db(): supplied argument is not a valid

MySQL-Link resource in /home/a4228948/public_html/imageid.php on line

10

Warning: mysql_close(): supplied argument is not a valid MySQL-Link

resource in /home/a4228948/public_html/imageid.php on line 29

<?PHP

error_reporting(E_ALL ^ E_DEPRECATED);

$user_name = "test";

$password = "protection";

$database = "temp";

$server = "mysql6.000webhost.com";

$db_handle = mysql_connect($server, $user_name, $password);

$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {

$SQL = "SELECT * FROM test";

$result = mysql_query($SQL);

while ( $db_field = mysql_fetch_assoc($result) ) {

print $db_field['id'] ;

}

mysql_close($db_handle);

}

else {

print "Database NOT Found ";

mysql_close($db_handle);

}

?>

网友答案:

Error in Your Username or Password. You check database Username and Password is correct . and server value set localhost

网友答案:

Only first error is really important at this point, the rest could be fine, but at the line 9 you won't connect, so nothing more be done with the DB.

Please double check that case is right etc. (depending on MySQL settings DB name can be case sensitive too), and that there are no extra spaces (happened to me a few times when copy-pasting).

Check that the DB actually exists (via phpMyAdmin or whatever your provider uses).

网友答案:

Check Database_name, Hostname and Login credentials (Username ans password) In term of case sensitive, spelling etc.

If you have correct credentials, database_name and Hostname then check permission of user and grant permission.

Try

GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'%' WITH GRANT OPTION;

This is how I create my "Super User" privileges (although I would normally specify a host). IMPORTANT NOTE

While this answer can solve the problem of access, WITH GRANT OPTION creates a MySQL user that can edit the permissions of other users.

The GRANT OPTION privilege enables you to give to other users or remove from other users those privileges that you yourself possess.

For security reasons, you should not use this type of user account for any process that the public will have access to (i.e. a website). It is recommended that you create a user with only database privileges for that kind of use.

grant all privileges on mydb.* to [email protected]'%' identified by 'mypasswd';
grant all privileges on mydb.* to [email protected] identified by 'mypasswd';

Warning 2 -

Change

$db_found = mysql_select_db($database, $db_handle);

to

$db_found  = mysql_select_db($database_spyware, $db_handle) || die(mysql_error());
分享给朋友:
您可能感兴趣的文章:
随机阅读: