﻿# SQLOP\_CONNECT

__

**xcall SQL, SQLOP\_CONNECT, cmdhdr, connectstring**

This operation establishes a connection to a specific database. 

**Parameters**

_cmdhdr_ (ST\_SQL\_CMDHDR), \[in/out\]

The fields of interest to this opcode in the _cmdhdr_ structure (defined in [SQL.DEF](https://bitbucket.org/microsabio/exlib/src/master/909060/sql.def)) are listed below.

| **Field** | **Dir** | **Notes** |
|------|------|------|
| handle | in | handle to connection (returned from SQLOP\_INIT\_CONN) |
| dbmsconid | in | [DBMS Connector ID](dbmsconnectorid.md) |
| opflags | in | For DBMSCONID\_MYSQL, you can optionally pass [MySQL Connection Flags](mysqlconnectionflags.md) |
| cmdarg1,2 | n/a |  |
| rc | out | return code (0 = ok, see SQLERR\_xxx) |
| rcext | out | extended error code |
| info1,2 | n/a |  |
| sqlstate | out | ANSI standard SQL state code |
| reshdl | n/a |  |
| psthdl | n/a |  |




_connectstring _\[string, in\]

A string containing command-line-style parameters needed to establish the connection. The general syntax consists of “-param=value” pairs, each separated by a space. The parameters include:

\-_host_

The hostname (or IP address) of the machine hosting the database server. For ODBC, specify the name of the data source. Note that depending on the data source configuration, it may eliminate the need to specify the login and/or database name. See _History_.

\-_user_

The user name to connect to the database. See _History_.

\-_pw_

The password to connect to the database. See _History_.

\-_db_

The database (or schema) name. If not specified, you can still connect to the server and then use SQL metadata queries, such as SHOW DATABASES (MySQL) to see which are available, and USE <table> to use a specific one.

\-_flags_

Optional connection flags, expressed as the decimal sum of MYCF\_xxx values (for MySQL) for the desired options (see Appendix)

\-_port_

Optional port number, required only when port is not the default value

**Examples**

connectstring = “-host=localhost  –user-me  –password=secret  db=sakila”

connectstring = “-host=Jack’s data source”  \! (ODBC)

connectstring = “Jack’s data source”  \! (ODBC) (_-host_= is optional)

**History**

2014 June, ashmysql connector version 1.4.193: The values of the -host, -user, and -pw and parameters may now be encrypted, using any of the 3 encryption modes supported described by MX\_PWCRYPT.