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')");
Sfili_81
  • 2,377
  • 8
  • 27
  • 36
  • _define("DB_HOST", "localhost");_ you have to set with online host. You have to set with the config data for your online database – Sfili_81 Oct 25 '19 at 07:48
  • I replaced the actual credentials whit fake ones, just for the sake of the example, but I checked and they are 100% correct. –  Oct 25 '19 at 07:51
  • Display php and mysql errors and you would not be in the dark... – Shadow Oct 25 '19 at 07:53
  • For testing, have you tried entering your connection details directly into mysqli_connect parameters? – Jaydee Oct 25 '19 at 08:36

1 Answers1

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);
equi
  • 729
  • 8
  • 19
  • I get : Warning: mysqli_connect(): (HY000/1045) . Denied access –  Oct 25 '19 at 08:01
  • Have you got your credentials correctly? Is address of your mysql server really localhost? – equi Oct 25 '19 at 08:03