Borrar filtros
Borrar filtros

please i need to know How connect sql with matlab???

3 visualizaciones (últimos 30 días)
Eman  Shaltout
Eman Shaltout el 28 de Feb. de 2012
Comentada: Walter Roberson el 4 de Mayo de 2016
i need to connect database with mat lap
that I create it with WampServer ....
please help me ..thank you first
[Information merged from duplicate question]
*i need to connect database with mat lap
that I create it with WampServer .... what drivers i need and from where i can get
please help me ..thank you first*

Respuesta aceptada

Geoff
Geoff el 2 de Mzo. de 2012
WampServer uses MySQL, I believe. You need to install the MySQL ODBC driver:
Then configure a new ODBC data source:
1. Run querybuilder from MatLab prompt.
2. In the 'query' menu, select 'Define ODBC Data Source...'
3. Click 'Add', select the MySQL ODBC driver and click 'Finish'
4. Give your data source a name and fill out the relevant fields for hostname, port (default: 3306), user, password, and database (schema name).
5. Hit OK and you now have a data source.
To connect, use the following command:
conn = database('datasourcename', '', '');
(replacing the text 'datasourcename' with the name you defined in step 4 above).
You should now have a connection to your database.
Now to do some query....
e = exec( conn, 'SELECT somefields FROM mytable' );
e = fetch(e);
close(e);
Your data is stored in e.Data.
You may also have to set some preferences. I prefer this:
s = struct;
s.DataReturnFormat = 'structure';
s.ErrorHandling = 'empty';
s.NullNumberRead = 'NaN';
s.NullNumberWrite = 'NaN';
s.NullStringRead = 'null';
s.NullStringWrite = 'null';
s.UseRegistryForSources = 'yes';
s.TempDirForRegistryOutput = 'C:\Temp';
s.DefaultRowPreFetch = '10000';
setdbprefs(s);
% Then make the database connection etc....
conn = database(.....);
I generally wrap all this up into a function:
function [data] = QueryAndFetchStruct( querystr )
Have fun =)
  1 comentario
Walter Roberson
Walter Roberson el 4 de Mayo de 2016
Lara Amro comments "Thank you so much you are a live saver !! "

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by