How to send a value from matlab to mysql?
2 views (last 30 days)
Show older comments
Hello,
I need to send the value handles.Data to my sql table, but I keep getting a error and don't know how to solve this problem. The value's that goes in to Data are coming from the arduino with a potmeter. And everything works except de sending part. So the function verstuur_calback and then the query=.... code doesn't work.
Could someone help me solve this? Maybe I need to put it in a for loop or something like that, but I don't know.
function inputdata_Callback(hObject, eventdata, handles)
% hObject handle to inputdata (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
board= arduino();
b=0;
for i= 1:1:10
analog= readVoltage (board, 'A0');
writePWMVoltage (board, 'D3', analog);
disp(['analog= ', num2str(analog)]);
pause(1);
A(i)= analog;
b= b+1;
B(i)= b;
end
A=A';
B=B';
handles.Data= [B A];
disp(handles.Data);
colnames= {'PK','Voltage'};
set(handles.uitable2,'data',handles.Data ,'ColumnName',colnames);
guidata(hObject, handles);
function verstuur_Callback(hObject, eventdata, handles)
% hObject handle to verstuur (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
gebruikersnaam= get(handles.edit_gebruikersnaam, 'String');
wachtwoord= get(handles.edit_wachtwoord, 'String');
datasource= get(handles.edit_tabel, 'String');
conn= database(datasource, gebruikersnaam, wachtwoord, handles.driver, handles.url);
query= ['INSERT INTO ' table ' VALUES (''''Data'''')'];
execute(conn,query);
close (conn);
2 Comments
Geoff Hayes
on 12 Apr 2019
Edited: Geoff Hayes
on 12 Apr 2019
Martijn - what is the full error message? Is the error from
query= ['INSERT INTO ' table ' VALUES (''''Data'''')'];
(not sure where Data is defined...)
Maybe Guillaume's answer at https://www.mathworks.com/matlabcentral/answers/455843-putting-two-seperate-columns-in-to-one-variable-and-how-to-insert-a-array-into-mysql will help. If this question is in response to his answer, then please further the conversation there rather than creating a new question.
Answers (0)
See Also
Categories
Find more on Database Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!