필터 지우기
필터 지우기

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

조회 수: 3 (최근 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 CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by