0

I can't connect to MySQL database, I triple checked that the credentials were correct and even contacted support from hosting: they told that it is probably a mistake in the MySql syntax- it works perfectly on local server but not online.

Do you see something suspicious?

 $DB_HOST=""; $DB_USER=""; $DB_PASSWORD=""; $DB_DATABASE=""; define("DB_HOST", "localhost"); define("DB_USER", "utente"); define("DB_PASSWORD", "password"); define("DB_DATABASE", "database"); $connessDB=mysqli_connect($DB_HOST,$DB_USER,$DB_PASSWORD,$DB_DATABASE); $toDB=mysqli_query($connessDB,"INSERT INTO utenti (nome, eta, citta, paese, mail, password, username) VALUES ('nome','eta','citta','paese','mail','password','username')"); 
4
  • define("DB_HOST", "localhost"); you have to set with online host. You have to set with the config data for your online database Commented Oct 25, 2019 at 7:48
  • I replaced the actual credentials whit fake ones, just for the sake of the example, but I checked and they are 100% correct. Commented Oct 25, 2019 at 7:51
  • Display php and mysql errors and you would not be in the dark... Commented Oct 25, 2019 at 7:53
  • For testing, have you tried entering your connection details directly into mysqli_connect parameters? Commented Oct 25, 2019 at 8:36

1 Answer 1

2

You defined constants with values, but still used variables for mysqli connection. Could you please try:

$connessDB=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE); 
Sign up to request clarification or add additional context in comments.

2 Comments

I get : Warning: mysqli_connect(): (HY000/1045) . Denied access
Have you got your credentials correctly? Is address of your mysql server really localhost?