Create a function for set name, user, password for sql database

Hi guys,
I want to create a file with a function inside for call every time a want to connect to a sql database inside of a script of a gui with manny connection.
Now I use this script to connect to it but when the password it's changed I must to change many places the pass:
conn = database('root', '****', '****');
curs = exec(conn, 'SELECT * FROM prices.prices order by Crt desc limit 200 ');
curs = fetch(curs);
close(curs);
data1 = curs.Data;
close(conn);
clear curs conn
If you could give me an example will be highly appreciated !
Thank you!
R2015a

 採用された回答

Rik
Rik 2022 年 6 月 13 日

1 投票

Why don't you use a variable that contains the password? Or a function that returns the password as a char array? That way you only have to change one place.

4 件のコメント

Cristian Martin
Cristian Martin 2022 年 6 月 13 日
That's a good idea! Thanks!
Cristian Martin
Cristian Martin 2022 年 6 月 13 日
@Rik but I use many callbacks in a gui and how can I call a variable from another callback section?
Cristian Martin
Cristian Martin 2022 年 6 月 13 日
I managed to do it with setappdata, thanks!
Rik
Rik 2022 年 6 月 13 日
Glad to be of help.
setappdata will work, but you can also store the password in one of the guidata fields. For general advice and examples for how to create a GUI (and avoid using GUIDE), have look at this thread.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

製品

リリース

R2015a

質問済み:

2022 年 6 月 12 日

コメント済み:

Rik
2022 年 6 月 13 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by