I can't send data to my mysql database
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
In my code I try to send data towards mysql database, but the mysql database doesn't receive it. And the odd thing is that I don't get an error, so I don't know whats wrong. If someone could please check this out and help me! The code below is just a small part of the code I wrote, but in this small part is somewhere a mistake. The value send gives this out:
send =
struct with fields:
Message: 'Invalid connection.'
% --- Executes on button press in inputdata.
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.voltage= A;
handles.pk= 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);
Data1 =[handles.pk, handles.voltage];
columnnames = {'PK', 'Voltage'};
tablename = 'Data';
values = compose('VALUES(%d, %d)', Data1); %note that the format depends on the type of data you insert %d works for INTEGER only
query = sprintf('InSERT INTO %s(%s) %s;', tablename, strjoin(columnnames, ', '), strjoin(values, ', '));
%query= ['INSERT INTO ' table ' VALUES (''''handles.Data'''')'];
send = exec(conn,query);
close (conn);
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Database Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!