Databases and Connections
This section describes the arguments used to build a connect string to a MySQL database. In order for a SourcePro DB application to interact with a database, an
RWDBDatabase instance must be created by calling:
RWDBManager::database(accessLib, serverName, userName,
passWord, databaseName, connectOptions);
All arguments are of type
RWCString. These parameters are passed to the MySQL C API function
mysql_real_connect().
The arguments you must provide to RWDBManager::database() are:
accessLib: If your DB Access Module for MySQL is compiled as a DLL or shared library, provide the name of the DLL or shared library. See the document
Building Your Applications for information about naming conventions. If you are using a static library, supply the string “
MYSQL”.
serverName: Supply the name or the IP address of the MySQL server to which you are connecting.
userName: Supply a valid MySQL login ID.
passWord: Supply the password for the user specified by
userName.
Note: You can instead provide a password using the callback API, which may provide more security. For more information, see Chapter 10, “Callbacks” in the DB Interface Module User’s Guide.
databaseName: Supply a valid database name. The
databaseName is required because of a restriction in
mysql_real_connect().
connectOptions: If the port number is other than the default, pass a string with the syntax
PORT=XXXX where
XXXX is the port number to use to connect to the server. For example:
PORT=3667 Example 1 – Opening a database
Here are two examples of opening a database.
The first example accesses a MySQL Server database using a shared build of the Access Module. A user name and password are provided. Notice that accessLib is defined as "mys<ver>15d.dll", indicating that the application will dynamically load the Access Module at runtime:
RWDBDatabase aDB = RWDBManager::database ("mys<ver>15d.dll",
"MySQL-Server", "cratchitt","scrooge", "");
The second example accesses MySQL Server using a static build of the Access Module. Notice that accessLib is defined as MYSQL, indicating that the application will use the static version of the Access Module:
RWDBDatabase aDB = RWDBManager::database ("MYSQL",
"192.168.1.100","cratchitt","scrooge", "");