from
mysql
by Jozef
very simple mysql class file for working with mysql databases.
|
| mysql |
classdef mysql<handle
%mysql class to handle MYSQL database
properties
dbconn
end
methods
function obj = mysql
try
obj.dbconn = database('name', 'user', 'password');
%isdbconn = isconnection(dbconn);
setdbprefs('DataReturnFormat', 'cellarray');
catch
error('Not possible to connect to MYSQL');
end
end
function delete(obj)
close(obj.dbconn)
end
function result = execute(obj,statement)
%execute the query using cursor
cursor = exec(obj.dbconn,statement);
try
data = fetch(cursor);
result = data.Data;
catch
end
try
close(cursor);
catch
end
end
function [exists] = tableExists(obj,table)
% [True,False] = table_exists(table,dbconn)
% Check if the SQL table exists
out = execute(obj,['show tables like "',char(table),'";']);
if strcmp(out,table)
exists = true;
else
exists= false;
end
end %table_exists
end %Methods
end %Class
|
|
Contact us at files@mathworks.com