Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

mysqlpp::Connection Class Reference

Manages the connection to the MySQL database. More...

#include <connection.h>

List of all members.

Public Methods

 Connection ()
 Create object without connecting it to the MySQL server.

 Connection (bool te)
 Connection (const char *db, const char *host="", const char *user="", const char *passwd="", bool te=true)
 For connecting to database without any special options.

 Connection (const char *db, const char *host, const char *user, const char *passwd, uint port, my_bool compress=0, unsigned int connect_timeout=60, bool te=true, cchar *socket_name=0, unsigned int client_flag=0)
 Connect to database, allowing you to specify all connection parameters.

bool connect (cchar *db="", cchar *host="", cchar *user="", cchar *passwd="")
 Open connection to MySQL database.

bool real_connect (cchar *db="", cchar *host="", cchar *user="", cchar *passwd="", uint port=0, my_bool compress=0, unsigned int connect_timeout=60, cchar *socket_name=0, unsigned int client_flag=0)
 Connect to database after object is created.

void close ()
 Close connection to MySQL server.

std::string info ()
 Calls MySQL C API function mysql_info() and returns result as a C++ string.

bool connected () const
 return true if connection was established successfully

bool success () const
 Return true if the last query was successful.

Query query ()
 Return a new query object.

 operator bool ()
 Alias for success().

const char * error ()
 Return last error message.


Detailed Description

Manages the connection to the MySQL database.


Constructor & Destructor Documentation

mysqlpp::Connection::Connection  
 

Create object without connecting it to the MySQL server.

Use real_connect() method to establish the connection.

mysqlpp::Connection::Connection bool    te
 

Same as default ctor except that it allows you to choose whether exceptions are enabled.

Parameters:
te  if true, exceptions are thrown on errors

mysqlpp::Connection::Connection const char *    db,
const char *    host = "",
const char *    user = "",
const char *    passwd = "",
bool    te = true
 

For connecting to database without any special options.

This constructor takes the minimum parameters needed for most programs' use of MySQL. There is a more complicated constructor that lets you specify everything that the C API function mysql_real_connect() does.

Parameters:
db  name of database to use
host  host name or IP address of MySQL server, or 0 if server is running on the same host as your program
user  user name to log in under, or 0 to use the user name this program is running under
passwd  password to use when logging in
te  if true, throw exceptions on errors

mysqlpp::Connection::Connection const char *    db,
const char *    host,
const char *    user,
const char *    passwd,
uint    port,
my_bool    compress = 0,
unsigned int    connect_timeout = 60,
bool    te = true,
cchar *    socket_name = 0,
unsigned int    client_flag = 0
 

Connect to database, allowing you to specify all connection parameters.

This constructor allows you to most fully specify the options used when connecting to the MySQL database. It is the thinnest layer in MySQL++ over the MySQL C API function mysql_real_connect().

Parameters:
db  name of database to use
host  host name or IP address of MySQL server, or 0 if server is running on the same host as your program
user  user name to log in under, or 0 to use the user name this program is running under
passwd  password to use when logging in
port  TCP port number MySQL server is listening on, or 0 to use default value
compress  if true, compress data passing through connection, to save bandwidth at the expense of CPU time
connect_timeout  max seconds to wait for server to respond to our connection attempt
te  if true, throw exceptions on errors
socket_name  Unix domain socket server is using, if connecting to MySQL server on the same host as this program running on, or 0 to use default name
client_flag  special connection flags. See MySQL C API documentation for mysql_real_connect() for details.


Member Function Documentation

void mysqlpp::Connection::close   [inline]
 

Close connection to MySQL server.

Closes the connection to the MySQL server.

bool mysqlpp::Connection::connect cchar *    db = "",
cchar *    host = "",
cchar *    user = "",
cchar *    passwd = ""
 

Open connection to MySQL database.

Open connection to the MySQL server, using defaults for all but the most common parameters. It's better to use one of the connect-on-create constructors if you can.

See this for parameter documentation.

bool mysqlpp::Connection::connected   const [inline]
 

return true if connection was established successfully

Returns:
true if connection was established successfully

const char* mysqlpp::Connection::error   [inline]
 

Return last error message.

Simply wraps mysql_error() in the C API.

mysqlpp::Connection::operator bool   [inline]
 

Alias for success().

Alias for success() member function. Allows you to have code constructs like this:

                    Connection conn;
                    .... use conn
                    if (conn) {
                        ... last SQL query was successful
                    }
                    else {
                        ... error occurred in SQL query
                    }

Query mysqlpp::Connection::query  
 

Return a new query object.

The returned query object is tied to this MySQL connection, so when you call a method like execute() on that object, the query is sent to the server this object is connected to.

bool mysqlpp::Connection::real_connect cchar *    db = "",
cchar *    host = "",
cchar *    user = "",
cchar *    passwd = "",
uint    port = 0,
my_bool    compress = 0,
unsigned int    connect_timeout = 60,
cchar *    socket_name = 0,
unsigned int    client_flag = 0
 

Connect to database after object is created.

It's better to use one of the connect-on-create constructors if you can.

Despite the name, this function is not a direct wrapper for the MySQL C API function mysql_real_connect(). It also sets some connection-related options using mysql_options().

See this for parameter documentation.

bool mysqlpp::Connection::success   const [inline]
 

Return true if the last query was successful.

Return true if the most recent query was successful


The documentation for this class was generated from the following files:
Generated on Thu May 5 05:31:23 2005 for MySQL++ by doxygen1.2.18