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

5 ビュー (過去 30 日間)
Eman  Shaltout
Eman Shaltout 2012 年 2 月 28 日
コメント済み: Walter Roberson 2016 年 5 月 4 日
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*

採用された回答

Geoff
Geoff 2012 年 3 月 2 日
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 件のコメント
Walter Roberson
Walter Roberson 2016 年 5 月 4 日
Lara Amro comments "Thank you so much you are a live saver !! "

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by