2

Im using LEMP (Ubuntu Linux server, Nginx, Mysql, PHP) in my machine

I have followed this tutorial to set it up https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-ubuntu-18-04

I can access mysql using command line (mysql -u user -p)

but if i run the php file in the commend line, or load it in the browser I get the following error

running the file in command line

php index.php
PHP Notice: PHP Warning: mysqli_connect(): (HY000/1045): Access denied for user 
'my_username'@'localhost' (using password: YES) in index.php on line 13

PHP code

$localhost = "localhost";
$username = "my_username";
$pass = "my_password";
$database = "my_database";
$con =  mysqli_connect($localhost, $username, $pass, $database) or die("not 
connect". mysqli_connect_error());

This answers didnt really help me MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES) I think my problem is that i need to enable mysql to allow php communications some how?

peter
  • 23
  • 3

1 Answers1

0

An Access denied error can have many causes. Often the problem is related to the MySQL accounts.

In this case if you have a variable declared as $pass = "pas$w" you will get a E_NOTICE. Undefined variable: w. But declaring that like 'pas$w' would be ok.

MySQL 5.7 (replace for your mysql version) MySQL Docs describe some courses of action you can take to correct the problem.

abestrad
  • 898
  • 2
  • 12
  • 23