Connecting with database

hi all,
I was triyng to connect with database with lolin d1 r1 mini. I am able to connect with router but can't connect with database.

This is the code that I am using, I took it from examples which are given and put it together.

Sorry for my bad english , and thanks. Gebruik code tags om code te formatteren voor het forum

#include <ESP8266WiFi.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>


// Replace with your network credentials
const char* ssid = "ssid";
const char* password = "password";

// Replace with your database credentials
IPAddress adres(127,0,0,1);  // IP address of database server
int port = 3306;
char* user = "root";
char* password_db = "";
char* database = "nameDB";



// Define MySQL objects
WiFiClient client;
MySQL_Connection conn(&client);
MySQL_Cursor* cursor;

void setup() {
  Serial.begin(115200);

  // Connect to Wi-Fi network
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");

  // Connect to database
  Serial.println("Connecting to database...");
  
  if (conn.connect(adres, port, user , password_db, database )) {
    Serial.println("Connected to database");
    cursor = new MySQL_Cursor(&conn);
  } else {
    Serial.println("Database connection failed");
  }
}

void loop() {
  // Your code goes here


}

Welcome to the forum

Your topic was MOVED to its current forum category which is more appropriate than the original as it is not an Introductory Tutorial

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.