ChuckBell / MySQL_Connector_Arduino

Database connector library for using MySQL with your Arduino projects.
333 stars 133 forks source link

help -- How to read config from a String #179

Closed wilson405 closed 2 years ago

wilson405 commented 2 years ago

hi, everything works perfectly, I just need a help, I need user and password, to be read from a string, because I will store it in Spiffs, can someone help me.

example :

// database user and password char user[] = here variable type String ;
char password[] = here variable type String;

ChuckBell commented 2 years ago

Hi. Can you be more specific? Maybe post a code snippet so I can see what you want to do? Otherwise, you may want to look at the sample sketches that show how to use a format string and sprintf() to fill in values.

On Oct 20, 2021, at 10:55 AM, wilson405 @.***> wrote:

hi, everything works perfectly, I just need a help, I need user and password, to be read from a string, because I will store it in Spiffs, can someone help me.

example :

char user[] = here string ; char password[] = here string;

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/179, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYHR5XQFWOY3LRVLHNDUH3J77ANCNFSM5GL3OWIQ.

wilson405 commented 2 years ago

Hi Sir ChuckBell,

in my code >

IPAddress server_addr(myserver); // IP of the MySQL server here char user[] = read string here; // MySQL user login username char password[] = read string here; // MySQL user login password char db[] = read string here; // MySQL Database

I would like to read the username, password and database from a String that I have stored in a variable, how do I convert the variable that is a String to the char * ? Would you help me ?

ChuckBell commented 2 years ago

I am not familiar with SPIFF (from the ESP world), but to convert a string to a char , you would use the c_str() method to get the char pointer.

For example, say you read the user name into a string something like this:

String user = something.spiff_read();

To use the user (which is a String class) as a char *, just call the c_str0 method like this:

connect(user.c_strr()...

There is no need to copy the string to a char * buffer.