0

Config file:

$db=array(
            'host'      =>      'localhost',
            'user'      =>      'root',
            'pass'      =>      'secret',
            'name'      =>      'jack',
    );

Index file

$mysql = new mysqli($db['host'],$db['user'],$db['pass'],$db['name']);
$mysql->set_charset('utf8mb4'); 
if($mysql->connect_errno)
{
    die('Database connection could not be established. Error number: '.$mysql->connect_errno);
}

I get:

Database connection could not be established. Error number: 1045

Please guys, tell me what to do and I will respond you with the answer in 30 seconds!

UPDATE:

Okay so if i make change line to

$mysql = new mysqli(localhost,root,secret,jack);

it works, but how do I get it work with the tags?

Petras
  • 19
  • 5
  • 1
    password `lavonas` or blank? or did u include config file in index file? – devpro Oct 21 '16 at 14:30
  • Probably you will need to read this: http://stackoverflow.com/questions/489119/mysql-error-1045-access-denied – nanocv Oct 21 '16 at 14:31
  • You are not getting any luck on this project are you. – RiggsFolly Oct 21 '16 at 14:35
  • yes there is a password in root, and the password is right. I don't know why im getting error – Petras Oct 21 '16 at 14:35
  • Can I suggest that you move this line `$mysql->set_charset('utf8mb4');` after you check the connection is OK. Dont think its the issue, but it is more logical – RiggsFolly Oct 21 '16 at 14:37
  • Try `print_r($db)` items and see if you really have them in the page, before trying to connect. – moni_dragu Oct 21 '16 at 14:38
  • Please show all the code. Is the `$db` array in the same code file as the connection? Is the connection code inside a function/method? I am thinking SCOPE issues here – RiggsFolly Oct 21 '16 at 14:39
  • **Scope** ___Scope___ _Scope_ scope.... Oh it might be a [scoping](http://php.net/manual/en/language.variables.scope.php) issue or then again its might be a [scope](http://php.net/manual/en/language.variables.scope.php) problem – RiggsFolly Oct 21 '16 at 14:40
  • 1
    _Okay so if i make change line to $mysql = new mysqli(localhost,root,secret,jack); it works, but how do I get it work with the tags?_ ===> it's clear you do not have the cofig file included correctly. – moni_dragu Oct 21 '16 at 14:40
  • **show ALL the code** not just a fragment – RiggsFolly Oct 21 '16 at 14:42
  • require_once 'include/config.php'; – Petras Oct 21 '16 at 14:43
  • Thats another fragment. Amend question. Show all the code – RiggsFolly Oct 21 '16 at 14:44
  • 3
    IMA F***** IDIOT, THREAD CLOSED – Petras Oct 21 '16 at 14:44
  • *IMA F***** IDIOT, THREAD CLOSED – Petras 4 secs ago* What is this @Petras. Explain. – Nana Partykar Oct 21 '16 at 14:45
  • 1
    @NanaPartykar OP has suddenly realised what they have done wrong, and they are felling a little silly not having noticed it before. **We all been there** – RiggsFolly Oct 21 '16 at 14:46
  • So, We should also know what he did wrong? I'm curious. – Nana Partykar Oct 21 '16 at 14:47
  • Okay, so basically i was configuring wrong config file, it had same name, but were on diferent folder. So yeah on the the i were requiring it had no mysql info whatsoever and that explains everything – Petras Oct 21 '16 at 14:51
  • It is impossible for `new mysqli(localhost,root,secret,jack);` to work -- there are no quotes around the arguments!! – Rick James Oct 22 '16 at 00:07

1 Answers1

0

Error No: 1045 refer to as Access denied for user 'root'@'localhost' (Using password: NO). so check you password and username for the database. Try passing the password as empty.

Priyadarshni
  • 184
  • 1
  • 13