PLS_Toolbox Documentation: builddbstr | < browse | calibsel > |
builddbstr
Purpose
Builds a database connection string.
Synopsis
str = builddbstr(dbstruct,options)
Description
This function is unsupported and is meant as a "simple" database connection tool. For more sophisticated connection tools and full support please see the Matlab Database Toolbox.
It is generally recommended that one use a Microsoft DSN (Data Source Name) to establish connection on Window platforms. These types of connections tend to be easier to maintain and more secure. For more information on DSN, see the Windows help entry for “ODBC”. Unix platforms should use JDBC, JDBC with MySQL is a "predefined" method and is known to work with the MySQL JDBC 3.51 Driver.
Input (dbstruct) can be:
1) A structure containing necessary information to construct one of the predefined connections listed below. The output will be a properly formatted connection string.
2) A string indicating a predefined structure to return. The output will be a structure containing predefined values along with empty fields that may need to be filled in. Fill in the EMPTY fields as needed and the connection should work. The 'user' and 'pw' fields are always present but may not be needed. This structure can be passed directly to querydb.m.
3) A structure with additional arg.value substructure fields necessary for a connection to a non-predefined database connection. The output will be a properly formatted connection string.
Input: (structure containing the following fields)
A connection will require one of more of the following fields. Empty values are not used.
EXAMPLE:
cnn.arg(1).name = 'PORT';
cnn.arg(1).value = '3306';
cnn.arg(2).name = 'SOCKET';
cnn.arg(2).value = '123';
Predefined Database Connections:
1) Microsoft Access : 'access' Uses standard connection provided with windows (Microsoft Access Driver (*.mdb)) and doesn't require UserID or PW if database doesn't have them defined.
2) Microsoft SQL Server : 'mssql' Not tested.
3) MySQL : 'mysql' Uses (MySQL ODBC 3.51 Driver) form mysql website. Must be downloaded and installed before making connection.
4) Data Source Name : 'dsn' Uses a Data Source Name defined in Windows ODBC Data Source Administrator dialog box. Although 'user' and 'pw' are returned in the structure they are generally not needed for DSN connections, this information is usually resides in the DSN itself.
5) MySQL(JDBC) : 'jmysql' Uses (MySQL JDBC 3.51 Driver) form mysql website. Must be downloaded and installed before making connection. The driver jar file must be added to the Matlab java classpath.
6) All : 'all' Show all available fields.
Options
Examples
Examples of building connection strings on a Windows machine for use with the querydb function. For Oracle and other database connections, try using DSN.
Microsoft Access on local machine:
>> cnstr = builddbstr('access')
cnstr =
provider: 'MSDASQL'
driver: '{Microsoft Access Driver (*.mdb)}'
location: ''
user: ''
pw: ''
>> cnstr.location = 'c:\temp\mydb.mdb';
MySQL on remote machine:
>> cnstr = builddbstr('mysql')
cnstr =
provider: 'MSDASQL'
driver: 'MySQL ODBC 3.51 Driver'
server: ''
dbname: ''
user: ''
pw: ''
>> cnstr.server = 'mydatabase.mywebsite.com';
>> cnstr.dbname = 'mydatabase';
>> cnstr.user = 'myname';
>> cnstr.pw = 'mypw';
MySQL on remote machine (JDBC on Windows):
>> cnstr = builddbstr('jmysql')
cnstr =
driver: 'com.mysql.jdbc.Driver'
server: ''
dbname: ''
user: ''
pw: ''
>> cnstr.server = 'mydatabase.mywebsite.com';
>> cnstr.dbname = 'mydatabase';
>> cnstr.user = 'myname';
>> cnstr.pw = 'mypw';
DSN (Data Source Name):
>> cnstr = builddbstr('dsn')
cnstr =
provider: 'MSDASQL'
dsn: ''
user: ''
pw: ''
>> cnstr.dsn = 'dsnname';
See Also
< browse | calibsel > |