Home > m > mysql > mysql_connect.m

mysql_connect

PURPOSE ^

MYSQL_CONNECT connects to an AO repository and returns the connection object.

SYNOPSIS ^

function [conn, dbuser] = mysql_connect(varargin)

DESCRIPTION ^

 MYSQL_CONNECT connects to an AO repository and returns the connection object.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: MYSQL_CONNECT connects to an AO repository and returns the
              connection object.

 CALL:        conn = mysql_connect(hostname, dbname)

 VERSION:     $Id: mysql_connect.m,v 1.5 2007/08/31 17:29:22 hewitson Exp $

 HISTORY:     24-05-2007 M Hewitson
                 Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [conn, dbuser] = mysql_connect(varargin)
0002 % MYSQL_CONNECT connects to an AO repository and returns the connection object.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: MYSQL_CONNECT connects to an AO repository and returns the
0007 %              connection object.
0008 %
0009 % CALL:        conn = mysql_connect(hostname, dbname)
0010 %
0011 % VERSION:     $Id: mysql_connect.m,v 1.5 2007/08/31 17:29:22 hewitson Exp $
0012 %
0013 % HISTORY:     24-05-2007 M Hewitson
0014 %                 Creation
0015 %
0016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0017 
0018 if nargin ~= 2
0019   error('### Incorrect inputs')
0020 end
0021 
0022 dbhost = varargin{1};
0023 dbname = varargin{2};
0024 
0025 %% Prompt for username and password
0026 
0027 [dbuser, dbpass] = logindlg('Title','LTPDA Repository Access');
0028 
0029 if isempty(dbuser) || isempty(dbpass)
0030   warning('!!! Login process cancelled.');
0031   conn = [];
0032   return
0033 end
0034 
0035 %% Database settings
0036 
0037 dbdriver = getappdata(0, 'mysql_driver');
0038 dburl    = sprintf('jdbc:mysql://%s/%s',dbhost,dbname);
0039 
0040 disp(sprintf('** Connecting to %s as %s...', dbhost, dbuser))
0041 
0042 conn     = database(dbname,dbuser,dbpass,dbdriver,dburl);
0043 
0044 disp('** Connection status:')
0045 disp(ping(conn))
0046 
0047 
0048 % END

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003