Hello Everyone

I am using this service 000webhosting.com to host my website. When I tried to connect to the database. I got this error

Could not connect to the database a7848759_lumos :SQLSTATE[28000] [1045] Access denied for user 'a7848759_fareedh'@'10.1.1.13' (using password: NO)

This is my code below

`<?php
`    $host = 'mysql1.000webhost.com';
`    $dbname = 'a7848759_lumos';
`    $username = 'a7848759_fareedh';
`    $password = '';
`try {
`   $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
`    echo "ITS WORKING!!";
`} catch (PDOException $pe) {
`    die("Could not connect to the database $dbname :" . $pe->getMessage());
`}

`?>`

Helppp...THANKS

Dani AI

Generated

The error shown (SQLSTATE[28000] [1045] — Access denied) means MySQL refused the connection because the credentials or the client host did not match an allowed user entry. The exception text that included “(using password: NO)” is the decisive clue: no password was sent, so the login was rejected. That matches ’s observation and complements ’s reminder that the MySQL host value must come from the host control panel, not guessed from the site domain. later corrected the empty password, which resolves the immediate failure.

A compact checklist for future readers and similar reports:

  • Confirm the exact DB host, database name, username and password shown in the hosting control panel; some hosts require “localhost” or a provider-specific hostname.
  • Verify the application actually supplies a non-empty password (the “using password: NO” message is diagnostic).
  • In phpMyAdmin (or the host panel) check the user’s Privileges and the Host column — the MySQL account must be allowed to connect from the webserver address (many shared hosts bind accounts to localhost or a specific host).
  • If credentials are edited in the control panel, recreate or reassign privileges instead of relying on data imports, since imports do not copy permissions.

Operational and security notes: never publish real credentials — rotate any password that was exposed on a forum. Store DB credentials outside the webroot or in environment vars, and grant the minimum privileges the application needs. When continued access problems occur despite correct credentials, confirm whether the script runs on the same server as the database (shared-hosting restrictions) and use the host panel’s “create user / grant privileges” workflow rather than manual SQL on a hosted account.

Recommended Answers

All 6 Replies

Are you sure that the database URL for $host is really that one? I doubt it is correct. The $host value is NOT the domain name, but it must be the database URL. The easiest way is to use the IP address. You need to check with your host for the real URL for database.

PS: NEVER post real user name, password, or even database name! You should change the user name now even though you change the password from empty to something else!

Yh, I will change it. I am just going to create a new user. The host name is mysql1.000webhost.com. MySQL host: mysql1.000webhost.com. That is the information displayed next to the username and password in my account

Member Avatar for Member #120589

This error usually arises when you don't have permission to access the db. I'm assuming that you copied the local db into the hosted db with phpmyadmin or something similar.

I would be very surprised if you had a remote db that did not have a password. Remember that only the data is copied when you import data - not permissions. If you don't get any joy, use phpmyadmin to create a new user and then use those credentials in your php scripts.

No, I created the database on the 000webhosting.com. I also created the username and the password for the databases. I am using the phpMyAdmin provided by the hosting company. Hence, I had to create a new username and password on the PhpMyAdmin and using those credientials in my connect.php

Member Avatar for Member #120589

Yes but you had this in your message:

(using password: NO)

So I'm assuming that you forgot to include it in $password

OHH GODD!! THAT WAS SOO STUPID OF ME!! THANKK YOUUUU!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.