# mysqlpp::TCPConnection Class Reference

Specialization of `Connection` for TCP/IP. More...

`#include <tcp_connection.h>`

Inheritance diagram for mysqlpp::TCPConnection:

[legend]
Collaboration diagram for mysqlpp::TCPConnection:

[legend]
List of all members.

## Public Member Functions

| TCPConnection ()
| Create object without connecting it to the MySQL server.
| TCPConnection (const char *addr, const char *db=0, const char *user=0, const char *password=0)
| Create object and connect to database server over TCP/IP in one step.
| TCPConnection (const TCPConnection &other)
| Establish a new connection using the same parameters as an existing connection.
| ~TCPConnection ()
| Destroy object.
bool | connect (const char *addr=0, const char *db=0, const char *user=0, const char *password=0)
| Connect to database after object is created.

## Static Public Member Functions

static bool | parse_address (std::string &addr, unsigned int &port, std::string &error)
| Break the given TCP/IP address up into a separate address and port form.

## Detailed Description

Specialization of `Connection` for TCP/IP.

This class just simplifies the connection creation interface of `Connection`. It does not add new functionality.

## Constructor & Destructor Documentation

mysqlpp::TCPConnection::TCPConnection | ( | const char * | addr,
|  | const char * | db = `0`,
|  | const char * | user = `0`,
|  | const char * | password = `0` |
| ) |  |  | `[inline]`

Create object and connect to database server over TCP/IP in one step.

Parameters:

  | addr | TCP/IP address of server, in either dotted quad form or as a host or domain name; may be followed by a colon and a port number or service name to override default port
  | db | name of database to use
  | user | user name to log in under, or 0 to use the user name the program is running under
  | password | password to use when logging in

BEWARE: These parameters are not in the same order as those in the corresponding constructor for Connection. This is a feature, not a bug. :)

mysqlpp::TCPConnection::TCPConnection | ( | const TCPConnection & | other | ) | `[inline]`

Establish a new connection using the same parameters as an existing connection.

Parameters:

  | other | pre-existing connection to clone

## Member Function Documentation

bool mysqlpp::TCPConnection::connect | ( | const char * | addr = `0`,
|  | const char * | db = `0`,
|  | const char * | user = `0`,
|  | const char * | password = `0` |
| ) |  |  |

Connect to database after object is created.

It's better to use the connect-on-create constructor if you can. See its documentation for the meaning of these parameters.

If you call this method on an object that is already connected to a database server, the previous connection is dropped and a new connection is established.

bool mysqlpp::TCPConnection::parse_address | ( | std::string & | addr,
|  | unsigned int & | port,
|  | std::string & | error |
| ) |  |  | `[static]`

Break the given TCP/IP address up into a separate address and port form.

Does some sanity checking on the address. Only intended to try and prevent library misuse, not ensure that the address can actually be used to contact a server.

It understands the following forms:

- 1.2.3.4

- a.b.com:89

- d.e.fr:mysvcname

It also understands IPv6 addresses, but to avoid confusion between the colons they use and the colon separating the address part from the service/port part, they must be in RFC 2732 form. Example: ``[2010:836B:4179::836B:4179]:1234

Parameters:

  | addr | the address and optional port/service combo to check on input, and the verified address on successful return
  | port | the port number (resolved from the service name if necessary) on successful return
  | error | on false return, reason for failure is placed here

Returns:
  false if address fails to pass sanity checks

The documentation for this class was generated from the following files:

- tcp_connection.h
- tcp_connection.cpp