views:

241

answers:

3
+4  Q: 

MySQL and Matlab

I want to interact with a MySQL database from Matlab.
I found a mysql "library" for matlab here and the same on mathworks.

I followed the instructions to compile the library and the compilation seems to be successful. I get a mex32 file at the end. Only, the instructions on the first page refer to a Dll that I need to use (I guess that a Dll was supposed to be generated).

I am not familiar with the mex compiler or with compiling external modules for Matlab.
Am I missing something trivial? Where is the Dll supposed to be?

Thanks.

A: 

OK, here is the solution to my problem.
The compilation does generate a mex32 file (32 is because I compiled it under a 32bit systme). You can check the output file of the compilation by running mexext. So apparently a mex32 file is a compiled version of the C file.
Once I placed the file in a directory that is in the Matlab's path it worked.

I guess the reference to the Dll in the link I provided is either obsolete or wrong.

Shaihi
Or, the documentation is confused and confusing -- a mex file is a DLL, on a Windows system. 'mex', the Matlab command, is really just a wrapper script which calls a compiler and passes it the correct flags and settings to create a DLL/mex file
High Performance Mark
+4  A: 

The reference to the dll is obsolete.

When you compile a mex function on Windows, you compile it as a dll (not an .exe). Thus, compiled mex functions used to have the extension .dll. Mex-functions with .dll extensions still work, but there is a warning that this might stop being the case in the future.

When 64-bit Windows arrived, TheMathWorks needed a way that people were to be able to compile the same mex-function for both Win32 and Win64, thus they changed the extension to .mexw32 and .mexw64, respectively. Apparently, they did not update the documentation completely.

Jonas
Thanks for the clarification.
Shaihi
+4  A: 

I'd recommend using java to connect MATLAB and MySQL (or any other db if required).

The java database connector is simple to set up. I built a simple java class to connect to the database - see previous posting for a crude but working solution.

The MATLAB code works as indicated

% include java class
import Jam.ConnectToDatabase

% set up database connection info
userName='myName';
userPassword='myPassword';
databaseUrl='jdbc:mysql://glnd2818898.internal.net/2000';

% create java class instance and open connection to the database
ctd = ConnectToDatabase;
ctd.openConnection(userName, userPassword, databaseUrl)

Once the connection is open I can then use the java methods to submit SQL queries, create tables, insert data etc. I'd never used java before but I downloaded Netbeans and I was away.

Adrian
+1 for the recommendation, even though this wasn't the question. I am not moving to this solution since the one I have right now works. The rating for it in the mathworks forums is high.
Shaihi
Thanks for that - whilst it's true that the only direct sentance with a question mark was "where is the dll supposed to be?" I was taking the problem to be at the higher level and getting MATLAB to interact with MySQL - effectively the title of your question. Having had problems with the mex compiler in the past then the alternative java solution side steps the mex problem. Still I've you've got it working then that's great.
Adrian