skip to Main Content

My database works fine when it runs on my mac on localhost. But when I upload the code with filezilla online, the following warning occurs:

"Warning: mysqli::__construct() [mysqli.construct]: 
(HY000/1045):Access denied for user 'root'@'localhost' (using 
password: YES) in /users/hassib/www/markme/index.php on line 248
Access denied for user 'root'@'localhost' (using password: YES)

The server I put the code on is hassib.bplaced.net. This is the code on line 248, which works fine on my mac on localhost.

$db = new mysqli('localhost','root','12345','markme');
if($db->connect_error):
  echo $db->connect_error;
endif;

Why does it work on my pc, but not when I upload it?

3

Answers


  1. first create database on live(online) and create user with username & password and add user for this database then provide this username & Password to mysqli() function

    Login or Signup to reply.
  2. “Warning: mysqli::__construct() [mysqli.construct]:
    (HY000/1045):Access denied for user ‘root’@’localhost’ (using
    password: YES) in /users/hassib/www/markme/index.php on line 248
    Access denied for user ‘root’@’localhost’ (using password: YES)

    From the error message above, it seems you are trying to connect with root user and not hassib

    • Make sure the database is created on your server.

    CREATE DATABASE markme;

    • Make sure you have granted privileges to user hassib on your server.

    GRANT ALL PRIVILEGES ON markme.* TO 'hassib'@'localhost' IDENTIFIED BY '12345';

    Login or Signup to reply.
  3. Are your sure that localhost is the correct host for your hosting provider? Some providers can provide another hosts for connection. Please, ask your provider for correct host.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search