please i need to know How connect sql with matlab???
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Eman Shaltout
il 28 Feb 2012
Commentato: Walter Roberson
il 4 Mag 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*
0 Commenti
Risposta accettata
Geoff
il 2 Mar 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 Commento
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Database Toolbox in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!