Access denied for user ''@'localhost' (using password: NO)

kittenparry

I have Ubuntu 14.04 LTS. I set up apache, phpmyadmin and mysql. I can access databases through localhost/phpmyadmin using my set password and root as username. I have put a link inside /etc/apache2/sites-enabled that links to the original .conf file of the website located in /etc/apache2/sites-available. And it has these lines (mypage.conf

php_value mysql.default.user    root
php_value mysql.default.password    mypass
php_value mysql.default.host    localhost

When I try to connect to database using this in my index.php it works prettily:

mysql_connect('localhost', 'root', 'mypass') or die(mysql_error());

But when I try to connect to database using this below:

mysql_connect(ini_get("mysql.default.host"), ini_get("mysql.default.user"), ini_get("mysql.default.password")) or die(mysql_error());

In return it posts this error message to the page and doesn't execute the rest of the code:

Access denied for user ''@'localhost' (using password: NO)

As I can understand from this, what it gets from default values are ''. So I must be doing something wrong about the .conf file. Can you help me about it?

kittenparry

As stated by @Vanitas, I changed the connection style to PDO instead of mysql. Here's my

connection.php

<?php
    DEFINE('DB_HOST', 'localhost');
    DEFINE('DB_NAME', 'mydb');
    DEFINE('DB_USER', 'usr');
    DEFINE('DB_PASS', 'pss');

    try{
        $db = new PDO('mysql:host='.DB_HOST.'; dbname='.DB_NAME, DB_USER, DB_PASS);
    }catch(PDOException $exeption){
        echo $exeption->getMessage(). '<br/>';
        die();
    }
?>

And I retrive it by using

require_once('../../0n/connection.php');

It's outside of the web directory. So, it's safe. I suppose. And it's working prettily.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Access denied for user 'root'@'localhost' (using password: NO);

From Dev

Access Denied for user 'linuxuser'@'localhost' (using password: no)

From Dev

access denied for user "@'localhost' (using password: no)

From Dev

MySQL Access denied for user 'User'@'localhost' (using password: YES)

From Dev

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

From Dev

Access denied for user 'root'@'localhost' (using password: YES)

From Java

Access denied for user 'homestead'@'localhost' (using password: YES)

From Java

Access Denied for User 'root'@'localhost' (using password: YES) - No Privileges?

From Dev

OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")

From Dev

Connection failed: Access denied for user ''username'@'localhost' (using password: YES)

From Dev

OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

From Dev

error: 'Access denied for user 'root'@'localhost' (using password: YES)'

From Dev

Could not connect to Database: Access denied for user '***'@'localhost' (using password: YES)

From Dev

Access denied for user ''@'localhost' (using password: NO) - trying to get an array

From Dev

mysql_query(): Access denied for user ''@'localhost' (using password: NO)

From Dev

OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

From Dev

Access denied for user 'root'@'localhost' (using password: Yes) after password reset LINUX

From Dev

Access denied for user 'sol0nig_User'@'localhost' (using password: YES)

From Dev

unable to connect MYSQL using PHP "Access denied for user ''@'localhost' (using password: NO)"

From Java

MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)

From Java

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

From Dev

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

From Dev

mysqlfailover command gives Error 1045: Access denied for user 'root'@'localhost' (using password: NO)

From Dev

ajax with jsp and mysql : java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

From Dev

Unexpected Exception: SQLSTATE[HY000] [1045] Access denied for user ****@'localhost' (using password: YES)

From Dev

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES)

From Dev

FOSUserBundle - SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO)

From Dev

PyCharm - Database connection. Access denied for user 'root'@'localhost' (using password: YES)

From Dev

Laravel 5.1 Forge - SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)

Related Related

  1. 1

    Access denied for user 'root'@'localhost' (using password: NO);

  2. 2

    Access Denied for user 'linuxuser'@'localhost' (using password: no)

  3. 3

    access denied for user "@'localhost' (using password: no)

  4. 4

    MySQL Access denied for user 'User'@'localhost' (using password: YES)

  5. 5

    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

  6. 6

    Access denied for user 'root'@'localhost' (using password: YES)

  7. 7

    Access denied for user 'homestead'@'localhost' (using password: YES)

  8. 8

    Access Denied for User 'root'@'localhost' (using password: YES) - No Privileges?

  9. 9

    OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")

  10. 10

    Connection failed: Access denied for user ''username'@'localhost' (using password: YES)

  11. 11

    OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

  12. 12

    error: 'Access denied for user 'root'@'localhost' (using password: YES)'

  13. 13

    Could not connect to Database: Access denied for user '***'@'localhost' (using password: YES)

  14. 14

    Access denied for user ''@'localhost' (using password: NO) - trying to get an array

  15. 15

    mysql_query(): Access denied for user ''@'localhost' (using password: NO)

  16. 16

    OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

  17. 17

    Access denied for user 'root'@'localhost' (using password: Yes) after password reset LINUX

  18. 18

    Access denied for user 'sol0nig_User'@'localhost' (using password: YES)

  19. 19

    unable to connect MYSQL using PHP "Access denied for user ''@'localhost' (using password: NO)"

  20. 20

    MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)

  21. 21

    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

  22. 22

    java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

  23. 23

    mysqlfailover command gives Error 1045: Access denied for user 'root'@'localhost' (using password: NO)

  24. 24

    ajax with jsp and mysql : java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

  25. 25

    Unexpected Exception: SQLSTATE[HY000] [1045] Access denied for user ****@'localhost' (using password: YES)

  26. 26

    Warning: mysqli_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES)

  27. 27

    FOSUserBundle - SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO)

  28. 28

    PyCharm - Database connection. Access denied for user 'root'@'localhost' (using password: YES)

  29. 29

    Laravel 5.1 Forge - SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)

HotTag

Archive