Hi,
I am curious as to why the variables 'user' and 'pass' are not recognized by Matlab in the following snippet. When the user launches the function, Matlab throws a undefined function or variable 'pben' where pben is the input from the user.
function update_table(user, pass)
% Info
username = user;
password = pass;
datasource = 'SGDOP';
% Connection and SQL query
conn = database(datasource, username, password);
sqlquery = ['SELECT * from table x'];
data = fetch(conn, sqlquery);
save('data.mat', 'data')
end

댓글 수: 4

Adam Danz
Adam Danz 2019년 8월 1일
편집: Adam Danz 2019년 8월 1일
"pben" is nowhere in this code so the error is coming from somehwere else unless "pben" is an undefined variable you're trying to pass into this function. How are you calling the function? It might be helpful to see the entire copy-pasted error message (all of it).
madhan ravi
madhan ravi 2019년 8월 1일
I'm not sure whether you're calling the function right, have a look at https://in.mathworks.com/help/matlab/matlab_prog/run-functions-in-the-editor.html on how to call a function properly.
Blue
Blue 2019년 8월 1일
Hi,
I am launching the function as update_tabel(pben, aaaa) where pben is the user and aaaa would be the password. Then the user and password are used to establish the connection to a database.
Adam Danz
Adam Danz 2019년 8월 1일
My bet is that when you call update_tabel(pben, aaaa), pben is not defined.

댓글을 달려면 로그인하십시오.

 채택된 답변

Steven Lord
Steven Lord 2019년 8월 1일

3 개 추천

My guess is that you're trying to call this function like:
update_table(pben, somePassword)
That attempts to pass the contents of the variable named pben or the result of calling a function named pben with 0 input arguments and 1 output argument into update_table. If you want to pass the literal text pben into the function, you need to specify it as a char vector or as a string.
update_table('pben', somePassword)
update_table("pben", somePassword)
If your password is not stored in a variable named somePassword but is the literal text somePassword, you need to pass that in as text as well.
update_table('pben', 'somePassword')
update_table("pben", "somePassword")

댓글 수: 1

Blue
Blue 2019년 8월 1일
Ah. That was embarrasingly simple. Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

태그

질문:

2019년 8월 1일

댓글:

2019년 8월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by