please i need to know How connect sql with matlab???
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Eman Shaltout
am 28 Feb. 2012
Kommentiert: Walter Roberson
am 4 Mai 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 Kommentare
Akzeptierte Antwort
Geoff
am 2 Mär. 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 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Database Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!