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


i trying connect mysql on server gives following error. user created , granted privileges.

its working on local machine not after deploying server.

also mysql_connect function works mysqli() gives access denied mentioned below.

also tried adding port.

any please.

help appreciated. thanks,

warning: mysqli::mysqli(): (hy000/1045): access denied user ''usernam'@'localhost' (using password: yes) in /home/domainname/public_html/autopublish/test.php on line 8 connection failed: access denied user ''username'@'localhost' (using password: yes)

<?php     $servername = "localhost";     $username = "'xxxxx";     $password = "xxxxx";     $dbname = "xxxxx";      // create connection     $conn = new mysqli($servername, $username, $password);  **//line 8**     // check connection     if ($conn->connect_error) {         die("connection failed: " . $conn->connect_error);     } else {         echo "no connection";     }      $sql = "select * pages";     $result = $conn->query($sql);      $data = array();     $arr = array();      if ($result->num_rows > 0) {         // output data of each row         while($row = $result->fetch_assoc()) {          }     } else {         echo "no token";     }     print_r(json_encode($data));     $conn->close();  ?> 

either user not have required rights database or password wrong.

otherwise remove user , use following statement create:

1.create user 'user'@'localhost' identified '123456789'; 2. 3.grant privileges on project.* 'user'@'localhost' grant option; 

or try this:

<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "dbname"; //create $conn = new mysqli($servername, $username, $password, $dbname); //check if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } echo "yaaay"; ?> 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -