function [out]=mysql_input(hostname,username,password,query,url)
% [out]=mysql_input(hostname,username,password,query,url)
% This function executes a list of MySql commands where no output is
% required (for example INSERT, UPDATE, ...).
% INPUT:
% hostname: 'localhost' or the host name string
% username: MySql username
% password: MySql password
% query: the list with MySql commands. Query is a cell.
% url: the URL of the .php file that is used to interface with MySql
% server
% OUTPUT:
% out: always set to 1
% Query escape string
L = length(query);
for ii=1:L
q = query{ii};
q = strrep(q, ' ', '_spazio_'); % ASCII code 32
q = strrep(q, '''', '_apice_'); % ASCII code 39
q = strrep(q, '\', '_slash_'); % ASCII code 92
q = strrep(q, '"', '_virgo_'); % ASCII code 34
q = strrep(q, '#', '_canc_'); % ASCII code 35
q = strrep(q, '%', '_perc_'); % ASCII code 37
q = strrep(q, '&', '_and_'); % ASCII code 38
query{ii} = q;
end
% Set POST parameters
opt{1} = 'hostname';
opt{2} = hostname;
opt{3} = 'username';
opt{4} = username;
opt{5} = 'password';
opt{6} = password;
L = length(query);
myquery = query{1};
for ii=2:L
myquery = strcat(myquery,'_pck_',query{ii});
end
opt{7} = 'myquery';
opt{8} = myquery;
% Retry to read the URL
done = 0;
while done==0
try
% Try to read the URL
HTML = urlread(url,'POST',opt);
done = 1;
catch
% If an error has occurred wait for some time before re-trying
disp('Error during URL reading. Retrying...');
done = 0;
pause(0.2);
end
end
out = 1;